2023-01-29 09:08:50 -05:00
|
|
|
import request from 'supertest';
|
2024-09-29 09:03:29 -05:00
|
|
|
import { describe, test } from 'vitest';
|
2023-01-29 09:08:50 -05:00
|
|
|
|
|
|
|
import { HTTP_STATUS } from '@verdaccio/core';
|
|
|
|
|
2023-07-08 12:06:03 -05:00
|
|
|
import { match } from '../src';
|
2023-01-29 09:08:50 -05:00
|
|
|
import { getApp } from './helper';
|
|
|
|
|
|
|
|
describe('match', () => {
|
|
|
|
test('should not match middleware', async () => {
|
|
|
|
const app = getApp([]);
|
|
|
|
app.param('_rev', match(/^-rev$/));
|
|
|
|
app.param('org_couchdb_user', match(/^org\.couchdb\.user:/));
|
|
|
|
app.get('/-/user/:org_couchdb_user', (req, res) => {
|
|
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use((res: any) => {
|
|
|
|
res.status(HTTP_STATUS.INTERNAL_ERROR);
|
|
|
|
});
|
|
|
|
|
|
|
|
return request(app).get('/-/user/test').expect(HTTP_STATUS.INTERNAL_ERROR);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should match middleware', async () => {
|
|
|
|
const app = getApp([]);
|
|
|
|
app.param('_rev', match(/^-rev$/));
|
|
|
|
app.get('/-/user/:_rev?', (req, res) => {
|
|
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use((res: any) => {
|
|
|
|
res.status(HTTP_STATUS.INTERNAL_ERROR);
|
|
|
|
});
|
|
|
|
|
|
|
|
return request(app).get('/-/user/-rev').expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
});
|