-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-list-dids: stream errors as view models and add tests for the…
… same #252
- Loading branch information
Showing
5 changed files
with
201 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import { BaseController } from '@/lib/sdk/controller' | ||
import { ListDIDsRequest } from '@/lib/core/usecase-models/list-dids-usecase-models' | ||
import appContainer from '@/lib/infrastructure/ioc/container-config' | ||
import CONTROLLERS from '@/lib/infrastructure/ioc/ioc-symbols-controllers' | ||
import { ListDIDsControllerParameters } from '@/lib/infrastructure/controller/list-dids-controller' | ||
import { NextApiResponse } from 'next' | ||
import { Readable } from 'stream' | ||
import { MockHttpStreamableResponseFactory } from 'test/fixtures/http-fixtures' | ||
import MockRucioServerFactory, { MockEndpoint } from 'test/fixtures/rucio-server' | ||
|
||
describe('DID API Tests', () => { | ||
beforeEach(() => { | ||
fetchMock.doMock() | ||
const listDIDsEndpoint: MockEndpoint = { | ||
url: `${MockRucioServerFactory.RUCIO_HOST}/dids/test/dids/search`, | ||
method: 'GET', | ||
includes: 'test/dids/search', | ||
response: { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/x-json-stream', | ||
}, | ||
body: Readable.from( | ||
[ | ||
'"dataset1"', | ||
'"dataset2"', | ||
'"dataset3"', | ||
" " | ||
].join('\n'), | ||
), | ||
}, | ||
} | ||
|
||
const dataset1StatusEndpoint: MockEndpoint = { | ||
url: `${MockRucioServerFactory.RUCIO_HOST}/dids/test/dataset1/status`, | ||
method: 'GET', | ||
response: { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
scope: 'test', | ||
name: 'dataset1', | ||
type: 'DATASET', | ||
account: 'root', | ||
open: true, | ||
monotonic: false, | ||
expired_at: 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(() => { | ||
fetchMock.dontMock() | ||
}) | ||
|
||
it('Should successfully stream DIDs', async () => { | ||
const res = MockHttpStreamableResponseFactory.getMockResponse() | ||
const listDIDsController = appContainer.get<BaseController<ListDIDsControllerParameters, ListDIDsRequest>>( | ||
CONTROLLERS.LIST_DIDS, | ||
) | ||
const controllerParams: ListDIDsControllerParameters = { | ||
response: res as unknown as NextApiResponse, | ||
rucioAuthToken: MockRucioServerFactory.VALID_RUCIO_TOKEN, | ||
query: "test:dataset1", | ||
type: "dataset" | ||
} | ||
await listDIDsController.execute( | ||
controllerParams, | ||
) | ||
|
||
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 | ||
|
||
|
||
expect(receivedData).toEqual([ | ||
{ | ||
"status": "success", | ||
"name": "dataset1", | ||
"scope": "test", | ||
"did_type": "Dataset", | ||
"bytes": 0, | ||
"length": 0, | ||
}, | ||
{ | ||
"status": "success", | ||
"name": "dataset2", | ||
"scope": "test", | ||
"did_type": "Dataset", | ||
"bytes": 123, | ||
"length": 456, | ||
}, | ||
{ | ||
"status": "success", | ||
"name": "dataset3", | ||
"scope": "test", | ||
"did_type": "Dataset", | ||
"bytes": 456, | ||
"length": 789, | ||
}, | ||
{ | ||
"status": "error", | ||
"name": "Gateway Error: Undefined DID in stream", | ||
"message": "Gateway recieved an invalid (undefined) DID for the query", | ||
"scope": "", | ||
"did_type": "Unknown", | ||
"bytes": 0, | ||
"length": 0, | ||
} | ||
]) | ||
}) | ||
}) |
1 change: 0 additions & 1 deletion
1
test/sdk/post-processing-streaming-pipeline/multicall-usecase-final-validation-error.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters