Skip to content

Commit

Permalink
api: fix list-did tests #226
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Jul 14, 2023
1 parent d9ee7b7 commit 4037f85
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 43 deletions.
9 changes: 0 additions & 9 deletions src/lib/core/use-case/list-dids/list-dids-usecase2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ class ListDIDsUseCase extends BaseMultiCallStreamableUseCase<ListDIDsRequest, Li
} as ListDIDsError
}

streamDataToStreamDTO(streamedChunk: ListDIDsStreamData, requestModel: ListDIDsRequest): DIDDTO {
const { scope, name } = parseDIDString(streamedChunk);
return {
name: name,
scope: scope,
did_type: requestModel.type,
} as DIDDTO
}

processStreamedData(dto: DIDDTO): { data: ListDIDsResponse | ListDIDsError; status: "success" | "error"; } {
const responseModel: ListDIDsResponse = {
status: 'success',
Expand Down
7 changes: 1 addition & 6 deletions src/lib/core/use-case/list-dids/pipeline-element-get-did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ export default class GetDIDsPipelineElement extends BaseStreamingPostProcessingP
super();
}
async makeGatewayRequest(requestModel: AuthenticatedRequestModel<ListDIDsRequest>, responseModel: ListDIDsResponse): Promise<DIDDTO> {
let scope: string = '';
let name: string = '';
try {
const parsedDID = parseDIDString(requestModel.query);
scope = parsedDID.scope;
name = parsedDID.name;
const dto: DIDDTO = await this.didGateway.getDID(requestModel.rucioAuthToken, scope, name);
const dto: DIDDTO = await this.didGateway.getDID(requestModel.rucioAuthToken, responseModel.scope, responseModel.name);
return dto;
} catch (error: any) {
const errorDTO: DIDDTO = {
Expand Down
6 changes: 0 additions & 6 deletions src/lib/sdk/usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,6 @@ export abstract class BaseMultiCallStreamableUseCase<
this.presenter.presentStream(this.finalResponseValidationTransform)
}

/**
* Convert the chunk returned from the gateway's stream to a DTO that will be passed forward in the current pipeline.
* @param streamedData The chunk returned from the gateway's stream
* @param requestModel The request model that was used to make the gateway request.
*/
abstract streamDataToStreamDTO(streamedData: TStreamData, requestModel?: TRequestModel): TStreamDTO

/**
* Validates the final response model after execution of all post processing pipeline elements.
Expand Down
82 changes: 60 additions & 22 deletions test/api/did/list-dids.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('DID API Tests', () => {
beforeEach(() => {
fetchMock.doMock()
const listDIDsEndpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/test/dids/search`,
url: `${MockRucioServerFactory.RUCIO_HOST}/dids/test/dids/search`,
method: 'GET',
includes: 'test/dids/search',
response: {
Expand All @@ -22,7 +22,7 @@ describe('DID API Tests', () => {
},
body: Readable.from(
[
'test:dateset1',
'test:dataset1',
'test:dataset2',
'test:dataset3',
].join('\n'),
Expand All @@ -31,7 +31,7 @@ describe('DID API Tests', () => {
}

const dataset1StatusEndpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/test/dataset1/status`,
url: `${MockRucioServerFactory.RUCIO_HOST}/dids/test/dataset1/status`,
method: 'GET',
response: {
status: 200,
Expand All @@ -46,15 +46,61 @@ describe('DID API Tests', () => {
open: true,
monotonic: false,
expired_at: null,
length: null,
bytes: null,
length: 0,
bytes: 0,
}),
},
}

const dataset2StatusEndpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/dids/test/dataset2/status`,
method: 'GET',
response: {
status: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
scope: 'test',
name: 'dataset2',
type: 'DATASET',
account: 'root',
open: true,
monotonic: false,
expired_at: null,
bytes: 123,
length: 456,
}),
},
}

const dataset3StatusEndpoint: MockEndpoint = {
url: `${MockRucioServerFactory.RUCIO_HOST}/dids/test/dataset3/status`,
method: 'GET',
response: {
status: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
scope: 'test',
name: 'dataset3',
type: 'DATASET',
account: 'root',
open: true,
monotonic: false,
expired_at: null,
bytes: 456,
length: 789,
}),
},
}

MockRucioServerFactory.createMockRucioServer(true, [
listDIDsEndpoint,
dataset1StatusEndpoint,
dataset2StatusEndpoint,
dataset3StatusEndpoint,
])
})
afterEach(() => {
Expand All @@ -76,11 +122,9 @@ describe('DID API Tests', () => {
controllerParams,
)

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

const done = new Promise<void>((resolve, reject) => {
Expand All @@ -96,18 +140,12 @@ describe('DID API Tests', () => {
})

await done
const str = "test:dataset1"
const json1 = JSON.stringify(str)
const str2 = JSON.parse(json1)
const json2 = JSON.stringify(str2)
const str3 = JSON.parse(json2)
expect(str3).toEqual("test:dataset1")
console.log(str3)


expect(receivedData).toEqual([
{
"status": "success",
"name": "dateset1",
"name": "dataset1",
"scope": "test",
"did_type": "Dataset",
"bytes": 0,
Expand All @@ -118,16 +156,16 @@ describe('DID API Tests', () => {
"name": "dataset2",
"scope": "test",
"did_type": "Dataset",
"bytes": 0,
"length": 0,
"bytes": 123,
"length": 456,
},
{
"status": "success",
"name": "dataset3",
"scope": "test",
"did_type": "Dataset",
"bytes": 0,
"length": 0,
"bytes": 456,
"length": 789,
}
])
})
Expand Down

0 comments on commit 4037f85

Please sign in to comment.