2020-06-30 21:55:14 +02:00
|
|
|
import supertest from 'supertest';
|
|
|
|
|
|
|
|
import { HTTP_STATUS } from '@verdaccio/commons-api';
|
2020-08-13 23:27:00 +02:00
|
|
|
import { HEADER_TYPE, HEADERS } from '@verdaccio/dev-commons';
|
|
|
|
import { $RequestExtend, $ResponseExtend } from '@verdaccio/dev-types';
|
|
|
|
import { initializeServer, publishTaggedVersion, publishVersion } from './_helper';
|
2020-06-30 21:55:14 +02:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
const mockApiJWTmiddleware = jest.fn(() => (req: $RequestExtend, res: $ResponseExtend, _next): void => {
|
|
|
|
req.remote_user = { name: 'foo', groups: [], real_groups: [] };
|
|
|
|
_next();
|
|
|
|
});
|
2020-06-30 21:55:14 +02:00
|
|
|
|
|
|
|
jest.mock('@verdaccio/auth', () => ({
|
2020-08-13 23:27:00 +02:00
|
|
|
Auth: class {
|
|
|
|
apiJWTmiddleware() {
|
|
|
|
return mockApiJWTmiddleware();
|
|
|
|
}
|
2020-08-19 20:27:35 +02:00
|
|
|
allow_access(_d, _f, cb) {
|
|
|
|
// always allow access
|
2020-08-13 23:27:00 +02:00
|
|
|
cb(null, true);
|
|
|
|
}
|
2020-08-19 20:27:35 +02:00
|
|
|
allow_publish(_d, _f, cb) {
|
|
|
|
// always allow publish
|
2020-08-13 23:27:00 +02:00
|
|
|
cb(null, true);
|
|
|
|
}
|
|
|
|
},
|
2020-06-30 21:55:14 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('package', () => {
|
2020-08-13 23:27:00 +02:00
|
|
|
let app;
|
2020-08-19 20:27:35 +02:00
|
|
|
beforeEach(async () => {
|
2020-08-13 23:27:00 +02:00
|
|
|
app = await initializeServer('package.yaml');
|
|
|
|
});
|
2020-06-30 21:55:14 +02:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
test('should return a package', async (done) => {
|
2020-08-19 20:27:35 +02:00
|
|
|
await publishVersion(app, 'package.yaml', 'foo', '1.0.0');
|
2020-08-13 23:27:00 +02:00
|
|
|
return 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');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-06-30 21:55:14 +02:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
test('should return a package by version', async (done) => {
|
2020-08-19 20:27:35 +02:00
|
|
|
await publishVersion(app, 'package.yaml', 'foo2', '1.0.0');
|
2020-08-13 23:27:00 +02:00
|
|
|
return supertest(app)
|
2020-08-19 20:27:35 +02:00
|
|
|
.get('/foo2/1.0.0')
|
2020-08-13 23:27:00 +02:00
|
|
|
.set('Accept', HEADERS.JSON)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
|
|
|
.then((response) => {
|
2020-08-19 20:27:35 +02:00
|
|
|
expect(response.body.name).toEqual('foo2');
|
2020-08-13 23:27:00 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-06-30 21:55:14 +02:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
// TODO: investigate the 404
|
|
|
|
test.skip('should return a package by dist-tag', async (done) => {
|
2020-08-19 20:27:35 +02:00
|
|
|
// await publishVersion(app, 'package.yaml', 'foo3', '1.0.0');
|
2020-08-13 23:27:00 +02:00
|
|
|
await publishVersion(app, 'package.yaml', 'foo-tagged', '1.0.0');
|
|
|
|
await publishTaggedVersion(app, 'package.yaml', 'foo-tagged', '1.0.1', 'test');
|
|
|
|
return supertest(app)
|
2020-08-19 20:27:35 +02:00
|
|
|
.get('/foo-tagged/1.0.1')
|
2020-08-13 23:27:00 +02:00
|
|
|
.set('Accept', HEADERS.JSON)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HTTP_STATUS.CREATED)
|
|
|
|
.then((response) => {
|
2020-08-19 20:27:35 +02:00
|
|
|
expect(response.body.name).toEqual('foo3');
|
2020-08-13 23:27:00 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-06-30 21:55:14 +02:00
|
|
|
|
2020-08-19 20:27:35 +02:00
|
|
|
test.skip('should return 404', async () => {
|
2020-08-13 23:27:00 +02:00
|
|
|
return supertest(app)
|
|
|
|
.get('/404-not-found')
|
|
|
|
.set('Accept', HEADERS.JSON)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HTTP_STATUS.NOT_FOUND);
|
|
|
|
});
|
2020-06-30 21:55:14 +02:00
|
|
|
});
|