From 885345f4cfe8d1a4bdce9dc7792dcf6dfc5120e2 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 28 Jan 2018 20:25:19 +0100 Subject: [PATCH] test(unit): add unit test for publish and unpublish --- test/unit/api.spec.js | 37 +++++++++++++++++++++ test/unit/partials/publish-api.js | 53 +++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 test/unit/partials/publish-api.js diff --git a/test/unit/api.spec.js b/test/unit/api.spec.js index fd0fdaaf8..a288dfda6 100644 --- a/test/unit/api.spec.js +++ b/test/unit/api.spec.js @@ -4,6 +4,7 @@ import path from 'path'; import rimraf from 'rimraf'; import configDefault from './partials/config'; +import publishMetadata from './partials/publish-api'; import Config from '../../src/lib/config'; import Storage from '../../src/lib/storage'; import Auth from '../../src/lib/auth'; @@ -446,4 +447,40 @@ describe('endpoint unit test', () => { }); + describe('should test publish api', () => { + test('should publish a new package', (done) => { + request(app) + .put('/@scope%2fpk1-test') + .set('content-type', 'application/json') + .send(JSON.stringify(publishMetadata)) + .expect(201) + .end(function(err, res) { + if (err) { + return done(err); + } + expect(res.body.ok).toBeDefined(); + expect(res.body.success).toBeDefined(); + expect(res.body.success).toBeTruthy(); + expect(res.body.ok).toMatch(/created new package/); + done(); + }); + }); + + test('should unpublish a new package', (done) => { + //FUTURE: for some reason it does not remove the scope folder + request(app) + .del('/@scope%2fpk1-test/-rev/4-6abcdb4efd41a576') + .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 removed/); + done(); + }); + }); + }); + }); diff --git a/test/unit/partials/publish-api.js b/test/unit/partials/publish-api.js new file mode 100644 index 000000000..92e67f2ce --- /dev/null +++ b/test/unit/partials/publish-api.js @@ -0,0 +1,53 @@ +const json = { + "_id": "@scope\/pk1-test", + "name": "@scope\/pk1-test", + "description": "", + "dist-tags": { + "latest": "1.0.6" + }, + "versions": { + "1.0.6": { + "name": "@scope\/pk1-test", + "version": "1.0.6", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + + ], + "author": { + "name": "Juan Picado", + "email": "juan@jotadeveloper.com" + }, + "license": "ISC", + "dependencies": { + "verdaccio": "^2.7.2" + }, + "readme": "# test", + "readmeFilename": "README.md", + "_id": "@scope\/pk1-test@1.0.6", + "_npmVersion": "5.5.1", + "_nodeVersion": "8.7.0", + "_npmUser": { + + }, + "dist": { + "integrity": "sha512-6gHiERpiDgtb3hjqpQH5\/i7zRmvYi9pmCjQf2ZMy3QEa9wVk9RgdZaPWUt7ZOnWUPFjcr9cmE6dUBf+XoPoH4g==", + "shasum": "2c03764f651a9f016ca0b7620421457b619151b9", + "tarball": "http:\/\/localhost:5555\/@scope\/pk1-test\/-\/@scope\/pk1-test-1.0.6.tgz" + } + } + }, + "readme": "# test", + "_attachments": { + "@scope\/pk1-test-1.0.6.tgz": { + "content_type": "application\/octet-stream", + "data": "H4sIAAAAAAAAE+2W32vbMBDH85y\/QnjQp9qxLEeBMsbGlocNBmN7bFdQ5WuqxJaEpGQdo\/\/79KPeQsnIw5KUDX\/9IOvurLuz\/DHSjK\/YAiY6jcXSKjk6sMqypHWNdtmD6hlBI0wqQmo8nVbVqMR4OsNoVB66kF1aW8eML+Vv10m9oF\/jP6IfY4QyyTrILlD2eqkcm+gVzpdrJrPz4NuAsULJ4MZFWdBkbcByI7R79CRjx0ScCdnAvf+SkjUFWu8IubzBgXUhDPidQlfZ3BhlLpBUKDiQ1cDFrYDmKkNnZwjuhUM4808+xNVW8P2bMk1Y7vJrtLC1u1MmLPjBF40+Cc4ahV6GDmI\/DWygVRpMwVX3KtXUCg7Sxp7ff3nbt6TBFy65gK1iffsN41yoEHtdFbOiisWMH8bPvXUH0SP3k+KG3UBr+DFy7OGfEJr4x5iWVeS\/pLQe+D+FIv\/agIWI6GX66kFuIhT+1gDjrp\/4d7WAvAwEJPh0u14IufWkM0zaW2W6nLfM2lybgJ4LTJ0\/jWiAK8OcMjt8MW3OlfQppcuhhQ6k+2OgkK2Q8DssFPi\/IHpU9fz3\/+xj5NjDf8QFE39VmE4JDfzPCBn4P4X6\/f88f\/Pu47zomiPk2Lv\/dOv8h+P\/34\/D\/p9CL+Kp67mrGDRo0KBBp9ZPsETQegASAAA=", + "length": 512 + } + } +} + +module.exports = json;