diff --git a/src/lib/constants.js b/src/lib/constants.js index dbdaf3737..152530be2 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -42,3 +42,5 @@ export const PACKAGE_ERROR = { NO_PACKAGE: 'no such package available', NOT_ALLOWED: 'not allowed to access package', }; + +export const DEFAULT_NO_README = 'ERROR: No README data found!'; diff --git a/test/functional/fixtures/package.js b/test/functional/fixtures/package.js index ad5a23019..12676ac85 100644 --- a/test/functional/fixtures/package.js +++ b/test/functional/fixtures/package.js @@ -4,6 +4,7 @@ module.exports = function(name, version = '0.0.0', port = PORT_SERVER_1, domain= return { name: name, version: version, + readme: "this is a readme", dist: { shasum: 'fake', tarball: `${domain}/${encodeURIComponent(name)}/-/blahblah`, diff --git a/test/functional/readme/pkg-no-readme.json b/test/functional/readme/pkg-no-readme.json new file mode 100644 index 000000000..f83b4f8d7 --- /dev/null +++ b/test/functional/readme/pkg-no-readme.json @@ -0,0 +1,56 @@ +{ + "_id": "readme-test-no-readme", + "name": "readme-test-no-readme", + "description": "", + "dist-tags": { + "foo": "0.0.0", + "latest": "0.0.0" + }, + "versions": { + "0.0.0": { + "name": "test-readme", + "version": "0.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "" + }, + "author": "", + "license": "ISC", + "_id": "test-readme@0.0.0", + "dist": { + "shasum": "8ee7331cbc641581b1a8cecd9d38d744a8feb863", + "tarball": "http:\/\/localhost:1234\/test-readme\/-\/test-readme-0.0.0.tgz" + }, + "_from": ".", + "_npmVersion": "1.3.1", + "_npmUser": { + "name": "alex", + "email": "alex@kocharin.ru" + }, + "maintainers": [ + { + "name": "juan", + "email": "juanpicado19@gmail.com" + } + ] + } + }, + "maintainers": [ + { + "name": "juan", + "email": "juanpicado19@gmail.com" + } + ], + "_attachments": { + "test-readme-0.0.0.tgz": { + "content_type": "application\/octet-stream", + "data": "H4sIAAAAAAAAA+2TsW7CMBCGM\/spTh6YKHUSIJLXqkPnrixWcIMLsS3btCDEu\/fs0Ba1SFVVVISUP8Odzqf\/zlY+K+qlaOSt7eLo2RudnVmMsel4DBjzasKOY1JZlJDlRVkU5aSspnnG8pIVOZ6fe5FTWvsgHK7yV5\/uLvARr0Q7qkUrKadB+mCXzY2Wr9q2TjZ0SF+k88poPGUj\/LAyl752yoauioVWqJgpPZcb\/Hmw0jV4ynfJEw9lvTAwo\/fOGcdBG4h18FbW6knJ+YzCYAByowLkdD+kTlrjVTBumzy2Nq7XqIDea7eKY7FJrMPCuG6Hlaql9rHr4fGO7i\/9pFcl+4X\/rWhX557xA\/9FVZ3gv+j5\/w9F+jl8g58c0OeQyCdH3HOglETsObxTTw7McwLJClt+wzz5JD45IPEcEHjMEfg0r8M9pQfaOSDs5NLP16tXr15XqzeJD6m5AAwAAA==", + "length": 352 + } + } +} diff --git a/test/functional/readme/readme.js b/test/functional/readme/readme.js index 2049cc061..4e40beea0 100644 --- a/test/functional/readme/readme.js +++ b/test/functional/readme/readme.js @@ -1,40 +1,46 @@ -import assert from 'assert'; -import {HEADERS} from '../../../src/lib/constants'; +import {DEFAULT_NO_README, HTTP_STATUS} from '../../../src/lib/constants'; export default function (server, server2) { describe('should test readme', () => { + const README_PKG1 = 'readme-test'; + const README_PKG2 = 'readme-test-no-readme'; - beforeAll(function() { - return server.request({ - uri: '/readme-test', - headers: { - 'content-type': HEADERS.JSON, - }, - method: 'PUT', - json: require('./pkg-readme.json'), - }).status(201); + beforeAll(async function() { + await server.putPackage('readme-test', require('./pkg-readme.json')) + .status(HTTP_STATUS.CREATED); + await server.putPackage(README_PKG2, require('./pkg-no-readme.json')) + .status(HTTP_STATUS.CREATED); }); test('add pkg', () => {}); describe('should check readme file', () => { - const matchReadme = (serverRef) => { + const matchReadme = (serverRef, pkgName = README_PKG1, readmeMessage = 'this is a readme') => { return serverRef.request({ - uri: '/-/verdaccio/package/readme/readme-test' - }).status(200).then(function(body) { - assert.equal(body, '

this is a readme

\n'); + uri: `/-/verdaccio/package/readme/${pkgName}` + }).status(HTTP_STATUS.OK).then(function(body) { + expect(body).toEqual(`

${readmeMessage}

\n`); }); }; - test('server1 - readme', () => { - return matchReadme(server); + test('should fetch server2 over uplink server1', () => { + return matchReadme(server, README_PKG1, 'this is a readme'); }); - test('server2 - readme', () => { - return matchReadme(server2); + test('should fetch package on local server1', () => { + return matchReadme(server2, README_PKG1, 'this is a readme'); }); + test('should fetch not found readme server2 over uplink server1', () => { + return matchReadme(server, README_PKG2, DEFAULT_NO_README); + }); + + test('should fetch not found readme package on local server1', () => { + return matchReadme(server2, README_PKG2, DEFAULT_NO_README); + }); + + }); }); }