0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00

refactor: readme test endpoit

add scenario when readme is not present
This commit is contained in:
Juan Picado @jotadeveloper 2018-06-22 21:22:32 +02:00
parent a1a70c973f
commit 495133edae
No known key found for this signature in database
GPG key ID: 18AC54485952D158
4 changed files with 84 additions and 19 deletions

View file

@ -42,3 +42,5 @@ export const PACKAGE_ERROR = {
NO_PACKAGE: 'no such package available', NO_PACKAGE: 'no such package available',
NOT_ALLOWED: 'not allowed to access package', NOT_ALLOWED: 'not allowed to access package',
}; };
export const DEFAULT_NO_README = 'ERROR: No README data found!';

View file

@ -4,6 +4,7 @@ module.exports = function(name, version = '0.0.0', port = PORT_SERVER_1, domain=
return { return {
name: name, name: name,
version: version, version: version,
readme: "this is a readme",
dist: { dist: {
shasum: 'fake', shasum: 'fake',
tarball: `${domain}/${encodeURIComponent(name)}/-/blahblah`, tarball: `${domain}/${encodeURIComponent(name)}/-/blahblah`,

View file

@ -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
}
}
}

View file

@ -1,40 +1,46 @@
import assert from 'assert'; import {DEFAULT_NO_README, HTTP_STATUS} from '../../../src/lib/constants';
import {HEADERS} from '../../../src/lib/constants';
export default function (server, server2) { export default function (server, server2) {
describe('should test readme', () => { describe('should test readme', () => {
const README_PKG1 = 'readme-test';
const README_PKG2 = 'readme-test-no-readme';
beforeAll(function() { beforeAll(async function() {
return server.request({ await server.putPackage('readme-test', require('./pkg-readme.json'))
uri: '/readme-test', .status(HTTP_STATUS.CREATED);
headers: { await server.putPackage(README_PKG2, require('./pkg-no-readme.json'))
'content-type': HEADERS.JSON, .status(HTTP_STATUS.CREATED);
},
method: 'PUT',
json: require('./pkg-readme.json'),
}).status(201);
}); });
test('add pkg', () => {}); test('add pkg', () => {});
describe('should check readme file', () => { describe('should check readme file', () => {
const matchReadme = (serverRef) => { const matchReadme = (serverRef, pkgName = README_PKG1, readmeMessage = 'this is a readme') => {
return serverRef.request({ return serverRef.request({
uri: '/-/verdaccio/package/readme/readme-test' uri: `/-/verdaccio/package/readme/${pkgName}`
}).status(200).then(function(body) { }).status(HTTP_STATUS.OK).then(function(body) {
assert.equal(body, '<p>this is a readme</p>\n'); expect(body).toEqual(`<p>${readmeMessage}</p>\n`);
}); });
}; };
test('server1 - readme', () => { test('should fetch server2 over uplink server1', () => {
return matchReadme(server); return matchReadme(server, README_PKG1, 'this is a readme');
}); });
test('server2 - readme', () => { test('should fetch package on local server1', () => {
return matchReadme(server2); 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);
});
}); });
}); });
} }