diff --git a/hub-js/src/local/mutation/delete-type-instance.ts b/hub-js/src/local/mutation/delete-type-instance.ts index 8eacb6b3d..240789346 100644 --- a/hub-js/src/local/mutation/delete-type-instance.ts +++ b/hub-js/src/local/mutation/delete-type-instance.ts @@ -41,11 +41,8 @@ export async function deleteTypeInstance( CALL { WITH ti WITH ti - MATCH (ti)-[:USES]->(others:TypeInstance) - MATCH (ti)-[:STORED_IN]->(backendRef: TypeInstanceBackendReference) - WITH backendRef, collect(others.id) as allUsedIds - WITH [x IN allUsedIds WHERE x <> backendRef.id ] as usedIds - RETURN usedIds + MATCH (others:TypeInstance)-[:USES]->(ti) + RETURN collect(others.id) as usedIds } CALL apoc.util.validate(size(usedIds) > 0, apoc.convert.toJson({ids: usedIds, code: 400}), null) diff --git a/hub-js/src/local/storage/service.ts b/hub-js/src/local/storage/service.ts index dcec79233..08a9ffaed 100644 --- a/hub-js/src/local/storage/service.ts +++ b/hub-js/src/local/storage/service.ts @@ -94,8 +94,8 @@ export default class DelegatedStorageService { * @param inputs - Describes what should be stored. * @returns The update backend's context. If there was no update, it's undefined. * - * TODO: validate if `input.value` is allowed by backend (`backend.acceptValue`) - * TODO: validate `input.backend.context` against `backend.contextSchema`. + * TODO(https://github.com/capactio/capact/issues/604): validate if `input.value` is allowed by backend (`backend.acceptValue`) + * TODO(https://github.com/capactio/capact/issues/604): validate `input.backend.context` against `backend.contextSchema`. */ async Store(...inputs: StoreInput[]): Promise { let mapping: UpdatedContexts = {}; @@ -138,8 +138,8 @@ export default class DelegatedStorageService { * * @param inputs - Describes what should be updated. * - * TODO: validate if `input.value` is allowed by backend (`backend.acceptValue`) - * TODO: validate `input.backend.context` against `backend.contextSchema`. + * TODO(https://github.com/capactio/capact/issues/604): validate if `input.value` is allowed by backend (`backend.acceptValue`) + * TODO(https://github.com/capactio/capact/issues/604): validate `input.backend.context` against `backend.contextSchema`. */ async Update(...inputs: UpdateInput[]) { for (const input of inputs) { @@ -149,7 +149,7 @@ export default class DelegatedStorageService { }); const cli = await this.getClient(input.backend.id); if (!cli) { - // TODO: remove after using a real backend in e2e tests. + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend in e2e tests. continue; } @@ -182,11 +182,11 @@ export default class DelegatedStorageService { }); const cli = await this.getClient(input.backend.id); if (!cli) { - // TODO: remove after using a real backend in e2e tests. + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend in e2e tests. result = { ...result, [input.typeInstance.id]: { - mockedKey: "mocked-val", + key: input.backend.id, }, }; continue; @@ -229,7 +229,7 @@ export default class DelegatedStorageService { }); const cli = await this.getClient(input.backend.id); if (!cli) { - // TODO: remove after using a real backend in e2e tests. + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend in e2e tests. continue; } @@ -255,7 +255,7 @@ export default class DelegatedStorageService { }); const cli = await this.getClient(input.backend.id); if (!cli) { - // TODO: remove after using a real backend in e2e tests. + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend in e2e tests. continue; } @@ -282,7 +282,7 @@ export default class DelegatedStorageService { }); const cli = await this.getClient(input.backend.id); if (!cli) { - // TODO: remove after using a real backend in e2e tests. + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend in e2e tests. continue; } @@ -325,7 +325,7 @@ export default class DelegatedStorageService { } const record = fetchRevisionResult.records[0]; - return record.get("value"); // TODO: validate against Storage JSON Schema. + return record.get("value"); // TODO(https://github.com/capactio/capact/issues/604): validate against Storage JSON Schema. } catch (e) { const err = e as Error; throw new Error( @@ -343,7 +343,7 @@ export default class DelegatedStorageService { logger.debug( "Skipping a real call as backend was classified as a fake one" ); - // TODO: remove after using a real backend in e2e tests. + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend in e2e tests. return undefined; } diff --git a/pkg/hub/client/local/client_test.go b/pkg/hub/client/local/client_test.go index ef70deca7..36ab8a846 100644 --- a/pkg/hub/client/local/client_test.go +++ b/pkg/hub/client/local/client_test.go @@ -369,20 +369,25 @@ func removeAllMembers(t *testing.T, cli *Client, familyDetails []gqllocalapi.Typ ctx := context.Background() - var parent string for _, member := range familyDetails { - if member.TypeRef.Path == "cap.type.parent" { - parent = member.ID // delete as the last one, to get rid of the problem that it is used by others + if member.TypeRef.Path != "cap.type.parent" { + defer func(id string) { // delay the child deletions + fmt.Println("Delete child", id) + err := cli.DeleteTypeInstance(ctx, id) + if err != nil { + t.Logf("err for %v: %v", id, err) + } + }(member.ID) + continue } + + fmt.Println("Delete parent", member.ID) + + // Delete parent first, to unblock deletion of children err := cli.DeleteTypeInstance(ctx, member.ID) if err != nil { t.Logf("err for %v: %v", member.ID, err) } } - - err := cli.DeleteTypeInstance(ctx, parent) - if err != nil { - t.Logf("err for %v: %v", parent, err) - } } diff --git a/test/e2e/action_test.go b/test/e2e/action_test.go index 104bd7f5f..7c9a72cec 100644 --- a/test/e2e/action_test.go +++ b/test/e2e/action_test.go @@ -132,6 +132,11 @@ var _ = Describe("Action", func() { By("8.1 Check uploaded TypeInstances") expUploadTIBackend = &hublocalgraphql.TypeInstanceBackendReference{ID: helmStorageTI.ID, Abstract: false} + + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend. + // for now, the Local Hub returns backend id under `key` property. + implIndicatorValue = expUploadTIBackend.ID + uploadedTI, cleanupUploaded = getUploadedTypeInstanceByValue(ctx, hubClient, implIndicatorValue) defer cleanupUploaded() // We need to clean it up as it's not deleted when Action is deleted. Expect(uploadedTI.Backend).Should(Equal(expUploadTIBackend)) @@ -194,6 +199,11 @@ var _ = Describe("Action", func() { By("4.1 Check uploaded TypeInstances") expUploadTIBackend := &hublocalgraphql.TypeInstanceBackendReference{ID: helmStorageTI.ID, Abstract: false} + + // TODO(https://github.com/capactio/capact/issues/604): remove after using a real backend. + // for now, the Local Hub returns backend id under `key` property. + implIndicatorValue = expUploadTIBackend.ID + uploadedTI, cleanupUploaded := getUploadedTypeInstanceByValue(ctx, hubClient, implIndicatorValue) defer cleanupUploaded() // We need to clean it up as it's not deleted when Action is deleted. Expect(uploadedTI.Backend).Should(Equal(expUploadTIBackend)) diff --git a/test/e2e/hub_test.go b/test/e2e/hub_test.go index 889ff4264..7c011dd61 100644 --- a/test/e2e/hub_test.go +++ b/test/e2e/hub_test.go @@ -322,9 +322,20 @@ var _ = Describe("GraphQL API", func() { createdTypeInstanceIDs, err := cli.CreateTypeInstances(ctx, createTypeInstancesInput()) Expect(err).NotTo(HaveOccurred()) - for _, ti := range createdTypeInstanceIDs { - defer deleteTypeInstance(ctx, cli, ti.ID) - } + defer func() { + var child string + for _, ti := range createdTypeInstanceIDs { + if ti.Alias == "child" { + child = ti.ID + continue + } + // Delete parent first, child TypeInstance is protected as it is used by parent. + deleteTypeInstance(ctx, cli, ti.ID) + } + + // Delete child TypeInstance as there are no "users". + deleteTypeInstance(ctx, cli, child) + }() parentTiID := findCreatedTypeInstanceID("parent", createdTypeInstanceIDs) Expect(parentTiID).ToNot(BeNil())