mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
NOISSUE - Remove name constrains (#2818)
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
This commit is contained in:
@@ -52,6 +52,8 @@ func TestSave(t *testing.T) {
|
||||
|
||||
repo := postgres.NewRepository(database)
|
||||
|
||||
duplicateChannelID := testsutil.GenerateUUID(t)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
channel channels.Channel
|
||||
@@ -124,6 +126,29 @@ func TestSave(t *testing.T) {
|
||||
resp: []channels.Channel{},
|
||||
err: repoerr.ErrMalformedEntity,
|
||||
},
|
||||
{
|
||||
desc: "add channel with duplicate name",
|
||||
channel: channels.Channel{
|
||||
ID: duplicateChannelID,
|
||||
Domain: validChannel.Domain,
|
||||
Name: validChannel.Name,
|
||||
Metadata: map[string]interface{}{"key": "different_value"},
|
||||
CreatedAt: validTimestamp,
|
||||
Status: channels.EnabledStatus,
|
||||
},
|
||||
resp: []channels.Channel{
|
||||
{
|
||||
ID: duplicateChannelID,
|
||||
Domain: validChannel.Domain,
|
||||
Name: validChannel.Name,
|
||||
Metadata: map[string]interface{}{"key": "different_value"},
|
||||
CreatedAt: validTimestamp,
|
||||
Status: channels.EnabledStatus,
|
||||
ConnectionTypes: []connections.ConnType{},
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
||||
@@ -53,6 +53,15 @@ func Migration() (*migrate.MemoryMigrationSource, error) {
|
||||
`DROP TABLE IF EXISTS connections`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "channels_02",
|
||||
Up: []string{
|
||||
`ALTER TABLE channels DROP CONSTRAINT IF EXISTS channels_domain_id_name_key`,
|
||||
},
|
||||
Down: []string{
|
||||
`ALTER TABLE channels ADD CONSTRAINT channels_domain_id_name_key UNIQUE (domain_id, name)`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
channelsMigration.Migrations = append(channelsMigration.Migrations, rolesMigration.Migrations...)
|
||||
|
||||
@@ -57,6 +57,8 @@ func TestClientsSave(t *testing.T) {
|
||||
domainID := testsutil.GenerateUUID(t)
|
||||
secret := testsutil.GenerateUUID(t)
|
||||
|
||||
duplicateClientID := testsutil.GenerateUUID(t)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
clients []clients.Client
|
||||
@@ -315,6 +317,20 @@ func TestClientsSave(t *testing.T) {
|
||||
},
|
||||
err: errors.ErrMalformedEntity,
|
||||
},
|
||||
{
|
||||
desc: "add client with duplicate name",
|
||||
clients: []clients.Client{
|
||||
{
|
||||
ID: duplicateClientID,
|
||||
Domain: validClient.Domain,
|
||||
Name: validClient.Name,
|
||||
Metadata: map[string]interface{}{"key": "different_value"},
|
||||
CreatedAt: validTimestamp,
|
||||
Status: clients.EnabledStatus,
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
rClients, err := repo.Save(context.Background(), tc.clients...)
|
||||
|
||||
@@ -56,6 +56,15 @@ func Migration() (*migrate.MemoryMigrationSource, error) {
|
||||
`DROP TABLE IF EXISTS connections`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "clients_02",
|
||||
Up: []string{
|
||||
`ALTER TABLE clients DROP CONSTRAINT IF EXISTS clients_domain_id_name_key`,
|
||||
},
|
||||
Down: []string{
|
||||
`ALTER TABLE clients ADD CONSTRAINT clients_domain_id_name_key UNIQUE (domain_id, name)`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ func TestSave(t *testing.T) {
|
||||
validChildGroupRes := validChildGroup
|
||||
validChildGroupRes.Path = fmt.Sprintf("%s.%s", pgroup.Path, validChildGroupRes.ID)
|
||||
validChildGroupRes.Level = 2
|
||||
duplicateGroupID := testsutil.GenerateUUID(t)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -199,6 +200,32 @@ func TestSave(t *testing.T) {
|
||||
},
|
||||
err: repoerr.ErrMalformedEntity,
|
||||
},
|
||||
{
|
||||
desc: "add group with duplicate name",
|
||||
group: groups.Group{
|
||||
ID: duplicateGroupID,
|
||||
Domain: validGroup.Domain,
|
||||
Name: validGroup.Name,
|
||||
Description: strings.Repeat("b", 64),
|
||||
Metadata: map[string]interface{}{"key": "different_value"},
|
||||
CreatedAt: validTimestamp,
|
||||
Status: groups.EnabledStatus,
|
||||
Path: duplicateGroupID,
|
||||
Level: 1,
|
||||
},
|
||||
resp: groups.Group{
|
||||
ID: duplicateGroupID,
|
||||
Domain: validGroup.Domain,
|
||||
Name: validGroup.Name,
|
||||
Description: strings.Repeat("b", 64),
|
||||
Metadata: map[string]interface{}{"key": "different_value"},
|
||||
CreatedAt: validTimestamp,
|
||||
Status: groups.EnabledStatus,
|
||||
Path: duplicateGroupID,
|
||||
Level: 1,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
||||
@@ -55,6 +55,15 @@ func Migration() (*migrate.MemoryMigrationSource, error) {
|
||||
`DROP EXTENSION IF EXISTS LTREE`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "groups_03",
|
||||
Up: []string{
|
||||
`ALTER TABLE groups DROP CONSTRAINT IF EXISTS groups_domain_id_name_key`,
|
||||
},
|
||||
Down: []string{
|
||||
`ALTER TABLE groups ADD CONSTRAINT groups_domain_id_name_key UNIQUE (domain_id, name)`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user