Skip to content

Commit

Permalink
tests: list-did-parent api tests #317
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Sep 12, 2023
1 parent 1fd2429 commit b0d8b97
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"jest.jestCommandLine": "npm run test:gateway -- --watch --env=jsdom",
"jest.jestCommandLine": "npm run test -- --watch --env=jsdom",
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ListDIDParentsInputPort } from "@/lib/core/port/primary/list-did-parent
import USECASE_FACTORY from "@/lib/infrastructure/ioc/ioc-symbols-usecase-factory";

export type ListDIDParentsControllerParameters = TAuthenticatedControllerParameters & {
rucioAuthToken: string,
scope: string,
name: string,
};
Expand Down
92 changes: 92 additions & 0 deletions test/api/did/list-did-parents.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import appContainer from "@/lib/infrastructure/ioc/container-config";
import CONTROLLERS from "@/lib/infrastructure/ioc/ioc-symbols-controllers";
import { BaseController } from "@/lib/sdk/controller";
import { NextApiResponse } from "next";
import { MockHttpStreamableResponseFactory } from "test/fixtures/http-fixtures";
import MockRucioServerFactory, { MockEndpoint } from "test/fixtures/rucio-server";
import { Readable } from "stream";
import { ListDIDParentsControllerParameters } from "@/lib/infrastructure/controller/list-did-parents-controller";
import { ListDIDParentsRequest } from "@/lib/core/usecase-models/list-did-parents-usecase-models";
import { DIDType } from "@/lib/core/entity/rucio";

describe("List DID Rules Feature tests", () => {
beforeEach(() => {
fetchMock.doMock();
const didListRulesMockEndpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/dids/test/file1/parents`,
method: "GET",
includes: "test/dataset1/rules",
response: {
status: 200,
headers: {
"Content-Type": "application/x-json-stream",
},
body: Readable.from( [
JSON.stringify({
"scope": "test",
"name": "dataset1",
"type": "DATASET"
}),
JSON.stringify({
"scope": "test",
"name": "dataset2",
"type": "DATASET"
})
].join("\n")),
},
};

MockRucioServerFactory.createMockRucioServer(true, [didListRulesMockEndpoint]);
});

afterEach(() => {
fetchMock.dontMock();
});
it("should list DID rules", async () => {
const res = MockHttpStreamableResponseFactory.getMockResponse();

const listDIDRulesController = appContainer.get<BaseController<ListDIDParentsControllerParameters, ListDIDParentsRequest>>(CONTROLLERS.LIST_DID_PARENTS);
const listDIDRulesControllerParams: ListDIDParentsControllerParameters = {
response: res as unknown as NextApiResponse,
rucioAuthToken: MockRucioServerFactory.VALID_RUCIO_TOKEN,
name: 'file1',
scope: 'test'
}

await listDIDRulesController.execute(listDIDRulesControllerParams);

const receivedData: any[] = []
const onData = (data: any) => {
receivedData.push(JSON.parse(data))
}

const done = new Promise<void>((resolve, reject) => {
res.on('data', onData)
res.on('end', () => {
res.off('data', onData)
resolve()
})
res.on('error', err => {
res.off('data', onData)
reject(err)
})
})

await done
console.log(receivedData)
expect(receivedData.length).toBe(2)
expect(receivedData[0]).toEqual({
"status": "success",
"scope": "test",
"name": "dataset1",
"did_type": DIDType.DATASET
})
expect(receivedData[1]).toEqual({
"status": "success",
"scope": "test",
"name": "dataset2",
"did_type": DIDType.DATASET
})

});
});

0 comments on commit b0d8b97

Please sign in to comment.