0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00

refactor: fix dist-tag tests

This commit is contained in:
Juan Picado @jotadeveloper 2017-08-13 17:36:10 +02:00 committed by juanpicado
parent 9c5eec1ca5
commit 121dc3c058
4 changed files with 61 additions and 66 deletions

View file

@ -171,7 +171,8 @@ class Storage {
* @param {*} callback * @param {*} callback
*/ */
replace_tags(name, tag_hash, callback) { replace_tags(name, tag_hash, callback) {
this.localStorage.replaceTags(name, tag_hash, callback); this.logger.warn('method deprecated');
this.localStorage.mergeTags(name, tag_hash, callback);
} }
/** /**

View file

@ -33,9 +33,9 @@
"tarball": "http://localhost:55551/__NAME__/-/blahblah" "tarball": "http://localhost:55551/__NAME__/-/blahblah"
} }
}, },
"1.1": { "1.1.0": {
"name": "__NAME__", "name": "__NAME__",
"version": "1.1", "version": "1.1.0",
"dist": { "dist": {
"shasum": "fake", "shasum": "fake",
"tarball": "http://localhost:55551/__NAME__/-/blahblah" "tarball": "http://localhost:55551/__NAME__/-/blahblah"
@ -43,7 +43,6 @@
} }
}, },
"dist-tags": { "dist-tags": {
"something": "0.1.1alpha", "latest": "1.1.0"
"bad": "1.1"
} }
} }

View file

@ -6,7 +6,7 @@ const _ = require('lodash');
const assert = require('assert'); const assert = require('assert');
const exec = require('child_process').exec; const exec = require('child_process').exec;
describe('Create registry servers', function() { describe('functional test verdaccio', function() {
const server = process.server; const server = process.server;
const server2 = process.server2; const server2 = process.server2;
const server3 = process.server3; const server3 = process.server3;

View file

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const _ = require('lodash');
const util = require('../lib/test.utils'); const util = require('../lib/test.utils');
const readTags = () => util.readFile('../fixtures/tags.json'); const readTags = () => util.readFile('../fixtures/tags.json');
@ -27,10 +28,9 @@ module.exports = function() {
return server.getPackage('testexp_tags') return server.getPackage('testexp_tags')
.status(200) .status(200)
.then(function(body) { .then(function(body) {
assert.equal(typeof(body.versions['1.1']), 'object'); assert(_.isObject(body.versions['1.1.0']));
assert.equal(body['dist-tags'].something, '0.1.1alpha');
// note: 5.4.3 is invalid tag, 0.1.3alpha is highest semver // note: 5.4.3 is invalid tag, 0.1.3alpha is highest semver
assert.equal(body['dist-tags'].latest, '0.1.3alpha'); assert.equal(body['dist-tags'].latest, '1.1.0');
assert.equal(body['dist-tags'].bad, null); assert.equal(body['dist-tags'].bad, null);
}); });
}); });
@ -49,29 +49,19 @@ module.exports = function() {
}); });
describe('dist-tags methods', function() { describe('dist-tags methods', function() {
before(function() { before(function() {
express.get('/testexp_tags2', function(req, res) { express.get('/testexp_tags2', function(req, res) {
let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags2'); let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags2');
res.send(JSON.parse(f)); res.send(JSON.parse(f));
}); });
}); });
// populate cache // populate cache
before(function() { before(function() {
return server.getPackage('testexp_tags2') return server.getPackage('testexp_tags2').status(200);
.status(200);
});
beforeEach(function() {
return server.request({
method: 'PUT',
uri: '/-/package/testexp_tags2/dist-tags',
json: {
foo: '0.1.0',
bar: '0.1.1alpha',
baz: '0.1.2',
},
}).status(201).body_ok(/tags updated/);
}); });
it('fetching tags', function() { it('fetching tags', function() {
@ -79,11 +69,11 @@ module.exports = function() {
method: 'GET', method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags', uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) { }).status(200).then(function(body) {
assert.deepEqual(body, const expected = {
{foo: '0.1.0', latest: "1.1.0"
bar: '0.1.1alpha', };
baz: '0.1.2',
latest: '0.1.3alpha'}); assert.deepEqual(body, expected);
}); });
}); });
@ -100,38 +90,18 @@ module.exports = function() {
method: 'GET', method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags', uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) { }).status(200).then(function(body) {
assert.deepEqual(body, const expected = {
{foo: '0.1.2', "latest": "1.1.0",
bar: '0.1.1alpha', "foo": "0.1.2",
baz: '0.1.2', "quux": "0.1.0"
quux: '0.1.0', };
latest: '0.1.3alpha'});
assert.deepEqual(body, expected);
}); });
}); });
}); });
it('replacing tags', function() { it('should add a dist-tag called foo', function() {
return server.request({
method: 'PUT',
uri: '/-/package/testexp_tags2/dist-tags',
json: {
foo: '0.1.2',
quux: '0.1.0',
},
}).status(201).body_ok(/updated/).then(function() {
return server.request({
method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) {
assert.deepEqual(body,
{foo: '0.1.2',
quux: '0.1.0',
latest: '0.1.3alpha'});
});
});
});
it('adding a tag', function() {
return server.request({ return server.request({
method: 'PUT', method: 'PUT',
uri: '/-/package/testexp_tags2/dist-tags/foo', uri: '/-/package/testexp_tags2/dist-tags/foo',
@ -141,16 +111,38 @@ module.exports = function() {
method: 'GET', method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags', uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) { }).status(200).then(function(body) {
assert.deepEqual(body, const expected = {
{foo: '0.1.3alpha', foo: '0.1.3alpha',
bar: '0.1.1alpha', quux: '0.1.0',
baz: '0.1.2', latest: '1.1.0'
latest: '0.1.3alpha'}); };
assert.deepEqual(body, expected);
}); });
}); });
}); });
it('removing a tag', function() { it('should remove a dis-tag called quux', function() {
return server.request({
method: 'DELETE',
uri: '/-/package/testexp_tags2/dist-tags/latest',
}).status(201).body_ok(/removed/).then(function() {
return server.request({
method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) {
const expected = {
latest: '1.1.0',
"quux": "0.1.0",
foo: "0.1.3alpha"
};
assert.deepEqual(body, expected);
});
});
});
it('should remove a dis-tag called foo', function() {
return server.request({ return server.request({
method: 'DELETE', method: 'DELETE',
uri: '/-/package/testexp_tags2/dist-tags/foo', uri: '/-/package/testexp_tags2/dist-tags/foo',
@ -159,12 +151,15 @@ module.exports = function() {
method: 'GET', method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags', uri: '/-/package/testexp_tags2/dist-tags',
}).status(200).then(function(body) { }).status(200).then(function(body) {
assert.deepEqual(body, const expected = {
{bar: '0.1.1alpha', latest: '1.1.0',
baz: '0.1.2', "quux": "0.1.0"
latest: '0.1.3alpha'}); };
assert.deepEqual(body, expected);
}); });
}); });
}); });
}); });
}; };