Skip to content

Commit

Permalink
Fix deletion, fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Mar 7, 2022
1 parent d8e8eab commit c845697
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
7 changes: 2 additions & 5 deletions hub-js/src/local/mutation/delete-type-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions hub-js/src/local/storage/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdatedContexts> {
let mapping: UpdatedContexts = {};
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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(
Expand All @@ -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;
}

Expand Down
21 changes: 13 additions & 8 deletions pkg/hub/client/local/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
10 changes: 10 additions & 0 deletions test/e2e/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 14 additions & 3 deletions test/e2e/hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit c845697

Please sign in to comment.