From 121dc3c058d84a60f12683eec04d133c0e96dcf2 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 13 Aug 2017 17:36:10 +0200 Subject: [PATCH] refactor: fix dist-tag tests --- src/lib/storage.js | 3 +- test/functional/fixtures/tags.json | 7 +- test/functional/index.js | 2 +- test/functional/tags/tags.js | 115 ++++++++++++++--------------- 4 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/lib/storage.js b/src/lib/storage.js index 182866c8f..18e0e4461 100644 --- a/src/lib/storage.js +++ b/src/lib/storage.js @@ -171,7 +171,8 @@ class Storage { * @param {*} 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); } /** diff --git a/test/functional/fixtures/tags.json b/test/functional/fixtures/tags.json index acfca60ac..4930e215e 100644 --- a/test/functional/fixtures/tags.json +++ b/test/functional/fixtures/tags.json @@ -33,9 +33,9 @@ "tarball": "http://localhost:55551/__NAME__/-/blahblah" } }, - "1.1": { + "1.1.0": { "name": "__NAME__", - "version": "1.1", + "version": "1.1.0", "dist": { "shasum": "fake", "tarball": "http://localhost:55551/__NAME__/-/blahblah" @@ -43,7 +43,6 @@ } }, "dist-tags": { - "something": "0.1.1alpha", - "bad": "1.1" + "latest": "1.1.0" } } diff --git a/test/functional/index.js b/test/functional/index.js index 1ac863f13..4fd41ea8a 100644 --- a/test/functional/index.js +++ b/test/functional/index.js @@ -6,7 +6,7 @@ const _ = require('lodash'); const assert = require('assert'); const exec = require('child_process').exec; -describe('Create registry servers', function() { +describe('functional test verdaccio', function() { const server = process.server; const server2 = process.server2; const server3 = process.server3; diff --git a/test/functional/tags/tags.js b/test/functional/tags/tags.js index 29a7636e9..0b9d70da0 100644 --- a/test/functional/tags/tags.js +++ b/test/functional/tags/tags.js @@ -1,6 +1,7 @@ 'use strict'; const assert = require('assert'); +const _ = require('lodash'); const util = require('../lib/test.utils'); const readTags = () => util.readFile('../fixtures/tags.json'); @@ -27,10 +28,9 @@ module.exports = function() { return server.getPackage('testexp_tags') .status(200) .then(function(body) { - assert.equal(typeof(body.versions['1.1']), 'object'); - assert.equal(body['dist-tags'].something, '0.1.1alpha'); + assert(_.isObject(body.versions['1.1.0'])); // 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); }); }); @@ -49,29 +49,19 @@ module.exports = function() { }); describe('dist-tags methods', function() { + before(function() { + express.get('/testexp_tags2', function(req, res) { let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags2'); res.send(JSON.parse(f)); }); + }); // populate cache before(function() { - return server.getPackage('testexp_tags2') - .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/); + return server.getPackage('testexp_tags2').status(200); }); it('fetching tags', function() { @@ -79,11 +69,11 @@ module.exports = function() { method: 'GET', uri: '/-/package/testexp_tags2/dist-tags', }).status(200).then(function(body) { - assert.deepEqual(body, - {foo: '0.1.0', - bar: '0.1.1alpha', - baz: '0.1.2', - latest: '0.1.3alpha'}); + const expected = { + latest: "1.1.0" + }; + + assert.deepEqual(body, expected); }); }); @@ -100,38 +90,18 @@ module.exports = function() { method: 'GET', uri: '/-/package/testexp_tags2/dist-tags', }).status(200).then(function(body) { - assert.deepEqual(body, - {foo: '0.1.2', - bar: '0.1.1alpha', - baz: '0.1.2', - quux: '0.1.0', - latest: '0.1.3alpha'}); + const expected = { + "latest": "1.1.0", + "foo": "0.1.2", + "quux": "0.1.0" + }; + + assert.deepEqual(body, expected); }); }); }); - it('replacing tags', 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() { + it('should add a dist-tag called foo', function() { return server.request({ method: 'PUT', uri: '/-/package/testexp_tags2/dist-tags/foo', @@ -141,16 +111,38 @@ module.exports = function() { method: 'GET', uri: '/-/package/testexp_tags2/dist-tags', }).status(200).then(function(body) { - assert.deepEqual(body, - {foo: '0.1.3alpha', - bar: '0.1.1alpha', - baz: '0.1.2', - latest: '0.1.3alpha'}); + const expected = { + foo: '0.1.3alpha', + quux: '0.1.0', + latest: '1.1.0' + }; + + 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({ method: 'DELETE', uri: '/-/package/testexp_tags2/dist-tags/foo', @@ -159,12 +151,15 @@ module.exports = function() { method: 'GET', uri: '/-/package/testexp_tags2/dist-tags', }).status(200).then(function(body) { - assert.deepEqual(body, - {bar: '0.1.1alpha', - baz: '0.1.2', - latest: '0.1.3alpha'}); + const expected = { + latest: '1.1.0', + "quux": "0.1.0" + }; + + assert.deepEqual(body, expected); }); }); }); + }); };