Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: request binary error #360

Merged
merged 8 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/port/controller/BinarySyncController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BinarySyncController extends AbstractController {
async listBinaries() {
return Object.entries(binaries).map(([ binaryName, binaryConfig ]) => {
return {
name: `${binaryName}}/`,
name: `${binaryName}/`,
category: `${binaryConfig.category}/`,
description: binaryConfig.description,
distUrl: binaryConfig.distUrl,
Expand Down
93 changes: 93 additions & 0 deletions test/port/controller/BinarySyncController/showBinary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,99 @@ describe('test/port/controller/BinarySyncController/showBinary.test.ts', () => {
}
});

it('should show valid root dirs', async () => {
await binaryRepository.saveBinary(Binary.create({
category: 'node-canvas-prebuilt',
parent: '/',
name: 'v2.6.1/',
isDir: true,
size: 0,
date: '2021-12-14T13:12:31.587Z',
}));
const res = await app.httpRequest()
.get('/-/binary/');
assert(res.status === 200);
assert(res.headers['content-type'] === 'application/json; charset=utf-8');
const items = res.body;
assert(items.length > 0);
for (const item of items) {
assert(item.type === 'dir');
assert(item.name);
assert(item.url);
assert(item.repoUrl);
assert(item.distUrl);
assert(item.description);
}

const item = items.filter((item: any) => item.name === 'nwjs/');
assert.deepStrictEqual(item, [{
name: 'nwjs/',
category: 'nwjs/',
description: 'NW.js (previously known as node-webkit) lets you call all Node.js modules directly from DOM and enables a new way of writing applications with all Web technologies.',
distUrl: 'https://dl.nwjs.io/',
repoUrl: 'https://github.com/nwjs/nw.js',
type: 'dir',
url: 'http://localhost:7001/-/binary/nwjs/',
}]);
});
it('should show valid sub dirs', async () => {
await binaryRepository.saveBinary(Binary.create({
category: 'node-canvas-prebuilt',
parent: '/',
name: 'v2.6.1/',
isDir: true,
size: 0,
date: '2021-12-14T13:12:31.587Z',
}));
const res = await app.httpRequest()
.get('/-/binary/node-canvas-prebuilt/');
assert(res.status === 200);
assert(res.headers['content-type'] === 'application/json; charset=utf-8');
const items = TestUtil.pickKeys(res.body, [ 'category', 'name', 'date', 'type', 'url' ]);
assert.deepStrictEqual(items, [{
category: 'node-canvas-prebuilt',
name: 'v2.6.1/',
date: '2021-12-14T13:12:31.587Z',
type: 'dir',
url: 'http://localhost:7001/-/binary/node-canvas-prebuilt/v2.6.1/',
}]);

});
it('should show valid files', async () => {
await binaryRepository.saveBinary(Binary.create({
category: 'node-canvas-prebuilt',
parent: '/',
name: 'v2.6.1/',
isDir: true,
size: 0,
date: '2021-12-14T13:12:31.587Z',
}));
await binaryRepository.saveBinary(Binary.create({
category: 'node-canvas-prebuilt',
parent: '/v2.6.1/',
name: 'node-canvas-prebuilt-v2.6.1-node-v57-linux-glibc-x64.tar.gz',
isDir: false,
size: 10,
date: '2021-12-14T13:12:31.587Z',
}));
const res = await app.httpRequest()
.get('/-/binary/node-canvas-prebuilt/v2.6.1/');
assert(res.status === 200);
assert(res.headers['content-type'] === 'application/json; charset=utf-8');
const items = TestUtil.pickKeys(res.body, [ 'category', 'name', 'date', 'type', 'url' ]);
assert(items.length > 0);

assert.deepStrictEqual(items, [
{
category: 'node-canvas-prebuilt',
name: 'node-canvas-prebuilt-v2.6.1-node-v57-linux-glibc-x64.tar.gz',
date: '2021-12-14T13:12:31.587Z',
type: 'file',
url: 'http://localhost:7001/-/binary/node-canvas-prebuilt/v2.6.1/node-canvas-prebuilt-v2.6.1-node-v57-linux-glibc-x64.tar.gz',
},
]);
});

it('should show node binaries', async () => {
app.mockHttpclient('https://nodejs.org/dist/index.json', 'GET', {
data: await TestUtil.readFixturesFile('nodejs.org/site/index.json'),
Expand Down