0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/packages/api/test/unit/validate.api.params.middleware.spec.ts
Juan Picado a7ba76423e refactor: test api refactor (#1826)
* test: add test for whoami

* Update middleware.ts

* test for user api

* more test for user api

* remove repeated code

* refactor

* Update index.spec.ts

* add package test

refactor others

* chore: upgrade deps

* chore: add test for package

* chore: update test

* update lock file

* Update ci.yml

* Update ci.yml

* Update package.spec.ts

* chore: update ci settings

* chore: update deps

* chore: update test
2021-04-09 17:54:11 +02:00

43 lines
1.2 KiB
TypeScript

/* eslint-disable curly */
// ensure that all arguments are validated
import path from 'path';
import fs from 'fs';
/**
* Validate.
app.param('package', validate_pkg);
app.param('filename', validate_name);
app.param('tag', validate_name);
app.param('version', validate_name);
app.param('revision', validate_name);
app.param('token', validate_name);
*/
describe('api endpoint app.param()', () => {
let m;
const requirePath = path.normalize(path.join(__dirname, '../../src/index.ts'));
const source = fs.readFileSync(requirePath, 'utf8');
const very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
const appParams = {};
while ((m = very_scary_regexp.exec(source)) != null) {
if (m[1] === 'set') {
continue;
}
let inner = m[2].slice(1, m[2].length - 1);
let t;
inner.split('/').forEach(function (x) {
t = x.match(/^:([^?:]*)\??$/);
if (m[1] === 'param') {
appParams[x] = 'ok';
} else if (t) {
appParams[t[1]] = appParams[t[1]] || m[0].trim();
}
});
}
test.each(Object.keys(appParams))('should validate ":%s"', (param) => {
expect(appParams[param]).toEqual('ok');
});
});