2018-06-22 07:49:10 +02:00
|
|
|
import {HEADERS, HTTP_STATUS, PORT_SERVER_1, PORT_SERVER_2} from '../../../src/lib/constants';
|
2017-12-02 09:52:40 +01:00
|
|
|
import {generateSha} from '../lib/test.utils';
|
2018-06-22 07:49:10 +02:00
|
|
|
import {DIST_TAGS} from "../../../src/lib/utils";
|
2017-07-25 20:14:51 +02:00
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
export default function(server, server2) {
|
2018-06-22 07:49:10 +02:00
|
|
|
const SCOPE = '@test/scoped';
|
|
|
|
const PKG_VERSION = '1.0.0';
|
|
|
|
const PKG_NAME = 'scoped';
|
2017-07-25 20:14:51 +02:00
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
describe('test-scoped', () => {
|
|
|
|
beforeAll(function() {
|
2017-07-25 20:14:51 +02:00
|
|
|
return server.request({
|
|
|
|
uri: '/@test%2fscoped',
|
|
|
|
headers: {
|
2018-04-30 15:41:04 +02:00
|
|
|
'content-type': HEADERS.JSON,
|
2017-07-25 20:14:51 +02:00
|
|
|
},
|
|
|
|
method: 'PUT',
|
|
|
|
json: require('./scoped.json'),
|
2018-06-22 07:49:10 +02:00
|
|
|
}).status(HTTP_STATUS.CREATED);
|
2017-07-25 20:14:51 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
test('should publish scope package', () => {});
|
2017-07-25 20:14:51 +02:00
|
|
|
|
|
|
|
describe('should get scoped packages tarball', () => {
|
|
|
|
const uploadScopedTarBall = (server) => {
|
2018-06-22 07:49:10 +02:00
|
|
|
return server.getTarball(SCOPE, `${PKG_NAME}-${PKG_VERSION}.tgz`)
|
|
|
|
.status(HTTP_STATUS.OK)
|
2017-07-25 20:14:51 +02:00
|
|
|
.then(function(body) {
|
|
|
|
// not real sha due to utf8 conversion
|
2018-06-22 07:49:10 +02:00
|
|
|
expect(generateSha(body)).toEqual('6e67b14e2c0e450b942e2bc8086b49e90f594790');
|
2017-07-25 20:14:51 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
test('should be a scoped tarball from server1', () => {
|
2017-07-25 20:14:51 +02:00
|
|
|
return uploadScopedTarBall(server);
|
|
|
|
});
|
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
test('should be a scoped tarball from server2', () => {
|
2017-07-25 20:14:51 +02:00
|
|
|
return uploadScopedTarBall(server2);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
describe('should retrieve scoped packages', () => {
|
2018-06-22 07:49:10 +02:00
|
|
|
const testScopePackage = (server, port) => server.getPackage(SCOPE)
|
|
|
|
.status(HTTP_STATUS.OK)
|
2017-07-25 20:14:51 +02:00
|
|
|
.then(function(body) {
|
2018-06-22 07:49:10 +02:00
|
|
|
expect(body.name).toBe(SCOPE);
|
|
|
|
expect(body.versions[PKG_VERSION].name).toBe(SCOPE);
|
|
|
|
expect(body.versions[PKG_VERSION].dist.tarball).toBe(
|
|
|
|
`http://localhost:${port}/@test%2fscoped/-/${PKG_NAME}-${PKG_VERSION}.tgz`);
|
|
|
|
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
|
2017-07-25 20:14:51 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
test('scoped package on server1', () => {
|
2018-06-22 07:49:10 +02:00
|
|
|
return testScopePackage(server, PORT_SERVER_1);
|
2017-07-25 20:14:51 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
test('scoped package on server2', () => {
|
2018-06-22 07:49:10 +02:00
|
|
|
return testScopePackage(server2, PORT_SERVER_2);
|
2017-07-25 20:14:51 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-02 09:52:40 +01:00
|
|
|
describe('should retrieve a scoped packages under nginx', () => {
|
|
|
|
test('should work nginx workaround', () => {
|
2017-07-25 20:14:51 +02:00
|
|
|
return server2.request({
|
|
|
|
uri: '/@test/scoped/1.0.0'
|
2018-06-22 07:49:10 +02:00
|
|
|
}).status(HTTP_STATUS.OK)
|
2017-07-25 20:14:51 +02:00
|
|
|
.then(function(body) {
|
2018-06-22 07:49:10 +02:00
|
|
|
expect(body.name).toEqual(SCOPE);
|
|
|
|
expect(body.dist.tarball).toEqual(
|
|
|
|
`http://localhost:${PORT_SERVER_2}/@test%2fscoped/-/${PKG_NAME}-${PKG_VERSION}.tgz`);
|
2017-07-25 20:14:51 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-12-02 09:52:40 +01:00
|
|
|
}
|