mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-17 07:45:52 +01:00
459b6fa72b
* Refactor local-storage async refactor local storage search stream Remove async from local-storage, refactor search with streams refactor search with undici fetch finish search refactor stream multiple request to single stream refactor storage types remove async dependency #1225 add score and refactor metadata remove old search async fix missing stream local data clean up clean up refactor folder search format fix some test fix issue on publish filter preview update ci delete package folder refactor refactor get packages methods fix tests fix lock file add changeset fix test windows disable some test update package json versions * fix merge * fix e2e cli * restore e2e * Update process.ts * Update process.ts * add improvement * format * Update utils.ts * test * test * Update search.spec.ts * Update search.spec.ts * Update search.spec.ts * test * Update ci.yml * clean up * fix tests * Update tags.ts * Update index.spec.ts * document changeset * format
91 lines
2.7 KiB
TypeScript
91 lines
2.7 KiB
TypeScript
import supertest from 'supertest';
|
|
|
|
import { HEADER_TYPE, HEADERS, HTTP_STATUS } from '@verdaccio/commons-api';
|
|
import { $ResponseExtend, $RequestExtend } from '../../types/custom';
|
|
import { initializeServer, publishTaggedVersion, publishVersion } from './_helper';
|
|
|
|
const mockApiJWTmiddleware = jest.fn(
|
|
() =>
|
|
(req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
|
req.remote_user = { name: 'foo', groups: [], real_groups: [] };
|
|
_next();
|
|
}
|
|
);
|
|
|
|
jest.mock('@verdaccio/auth', () => ({
|
|
Auth: class {
|
|
apiJWTmiddleware() {
|
|
return mockApiJWTmiddleware();
|
|
}
|
|
allow_access(_d, _f, cb) {
|
|
// always allow access
|
|
cb(null, true);
|
|
}
|
|
allow_publish(_d, _f, cb) {
|
|
// always allow publish
|
|
cb(null, true);
|
|
}
|
|
},
|
|
}));
|
|
|
|
describe('package', () => {
|
|
let app;
|
|
beforeEach(async () => {
|
|
app = await initializeServer('package.yaml');
|
|
});
|
|
|
|
test('should return a package', async () => {
|
|
await publishVersion(app, 'package.yaml', 'foo', '1.0.0');
|
|
return new Promise((resolve) => {
|
|
supertest(app)
|
|
.get('/foo')
|
|
.set('Accept', HEADERS.JSON)
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
.expect(HTTP_STATUS.OK)
|
|
.then((response) => {
|
|
expect(response.body.name).toEqual('foo');
|
|
resolve(response);
|
|
});
|
|
});
|
|
});
|
|
|
|
test('should return a package by version', async () => {
|
|
await publishVersion(app, 'package.yaml', 'foo2', '1.0.0');
|
|
return new Promise((resolve) => {
|
|
supertest(app)
|
|
.get('/foo2/1.0.0')
|
|
.set('Accept', HEADERS.JSON)
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
.expect(HTTP_STATUS.OK)
|
|
.then((response) => {
|
|
expect(response.body.name).toEqual('foo2');
|
|
resolve(response);
|
|
});
|
|
});
|
|
});
|
|
|
|
// FIXME: investigate the 404
|
|
test.skip('should return a package by dist-tag', async (done) => {
|
|
// await publishVersion(app, 'package.yaml', 'foo3', '1.0.0');
|
|
await publishVersion(app, 'package.yaml', 'foo-tagged', '1.0.0');
|
|
await publishTaggedVersion(app, 'package.yaml', 'foo-tagged', '1.0.1', 'test');
|
|
return supertest(app)
|
|
.get('/foo-tagged/1.0.1')
|
|
.set('Accept', HEADERS.JSON)
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
.expect(HTTP_STATUS.CREATED)
|
|
.then((response) => {
|
|
expect(response.body.name).toEqual('foo3');
|
|
done();
|
|
});
|
|
});
|
|
|
|
test('should return 404', async () => {
|
|
return supertest(app)
|
|
.get('/404-not-found')
|
|
.set('Accept', HEADERS.JSON)
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
.expect(HTTP_STATUS.NOT_FOUND);
|
|
});
|
|
});
|