mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
test(dist-tag): add unit test for dist-tag
This commit is contained in:
parent
ec36521ab8
commit
234299fe2a
3 changed files with 118 additions and 5 deletions
|
@ -5,7 +5,6 @@ const mime = require('mime');
|
|||
const _ = require('lodash');
|
||||
|
||||
const media = Middleware.media;
|
||||
const expect_json = Middleware.expect_json;
|
||||
|
||||
module.exports = function(route, auth, storage) {
|
||||
const can = Middleware.allow(auth);
|
||||
|
@ -63,8 +62,7 @@ module.exports = function(route, auth, storage) {
|
|||
});
|
||||
});
|
||||
|
||||
route.post('/-/package/:package/dist-tags', can('publish'), media(mime.getType('json')), expect_json,
|
||||
function(req, res, next) {
|
||||
route.post('/-/package/:package/dist-tags', can('publish'), function(req, res, next) {
|
||||
storage.merge_tags(req.params.package, req.body, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
/* eslint prefer-rest-params: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const _ = require('lodash');
|
||||
const createError = require('http-errors');
|
||||
|
|
|
@ -244,6 +244,21 @@ describe('endpoint unit test', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should fails on fetch jquery specific tag package from remote uplink', (done) => {
|
||||
|
||||
request(app)
|
||||
.get('/jquery/never-will-exist-this-tag')
|
||||
.set('content-type', 'application/json; charset=utf-8')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(404)
|
||||
.end(function(err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should not found a unexisting remote package under scope', (done) => {
|
||||
|
||||
request(app)
|
||||
|
@ -307,4 +322,106 @@ describe('endpoint unit test', () => {
|
|||
|
||||
});
|
||||
|
||||
describe('should test dist-tag api', () => {
|
||||
const jqueryVersion = '2.1.2';
|
||||
const jqueryUpdatedVersion = {
|
||||
'beta': '3.0.0',
|
||||
'jota': '1.6.3'
|
||||
};
|
||||
|
||||
test('should set a new tag on jquery', (done) => {
|
||||
|
||||
request(app)
|
||||
.put('/jquery/verdaccio-tag')
|
||||
.send(JSON.stringify(jqueryVersion))
|
||||
.set('accept', 'gzip')
|
||||
.set('accept-encoding', 'application/json')
|
||||
.set('content-type', 'application/json')
|
||||
.expect(201)
|
||||
.end(function(err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.ok).toMatch(/package tagged/);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should fetch all tag for jquery', (done) => {
|
||||
|
||||
request(app)
|
||||
.get('/-/package/jquery/dist-tags')
|
||||
.set('accept-encoding', 'application/json')
|
||||
.set('content-type', 'application/json')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(res.body).toBeDefined();
|
||||
expect(res.body['verdaccio-tag']).toMatch(jqueryVersion);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should update a new tag on jquery', (done) => {
|
||||
|
||||
request(app)
|
||||
.post('/-/package/jquery/dist-tags')
|
||||
.send(JSON.stringify(jqueryUpdatedVersion))
|
||||
.set('content-type', 'application/json')
|
||||
.expect(201)
|
||||
.end(function(err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.ok).toMatch(/tags updated/);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should fetch all tags for jquery and ccheck previous update', (done) => {
|
||||
|
||||
request(app)
|
||||
.get('/-/package/jquery/dist-tags')
|
||||
.set('accept-encoding', 'application/json')
|
||||
.set('content-type', 'application/json')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(res.body).toBeDefined();
|
||||
expect(res.body['beta']).toMatch(jqueryUpdatedVersion['beta']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should set a remove a tag on jquery', (done) => {
|
||||
|
||||
request(app)
|
||||
.del('/-/package/jquery/dist-tags/verdaccio-tag')
|
||||
.set('accept-encoding', 'application/json')
|
||||
.set('content-type', 'application/json')
|
||||
//.expect('Content-Type', /json/)
|
||||
.expect(201)
|
||||
.end(function(err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
expect(res.body.ok).toBeDefined();
|
||||
expect(res.body.ok).toMatch(/tag removed/);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue