mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
test: add tests for routes
This commit is contained in:
committed by
Rainer Killinger
parent
751693bebc
commit
d3955b3cdd
@@ -31,6 +31,7 @@ export const bulkAddRouter = createRoute<SCBulkAddRequest, SCBulkAddResponse>(
|
||||
bulkRouteModel,
|
||||
async (request, app, params) => {
|
||||
|
||||
// TODO: DELETE as not used
|
||||
if (typeof params === 'undefined' || typeof params.UID !== 'string') {
|
||||
throw new Error('UID of Bulk was not given, but route with obligatory parameter was called');
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ export const bulkDoneRouter = createRoute<SCBulkDoneRequest, SCBulkDoneResponse>
|
||||
bulkDoneRouteModel,
|
||||
async (_request, app, params) => {
|
||||
|
||||
// TODO: DELETE as not used
|
||||
if (typeof params === 'undefined' || typeof params.UID !== 'string') {
|
||||
throw new Error('UID of Bulk was not given, but route with obligatory parameter was called');
|
||||
}
|
||||
|
||||
@@ -13,33 +13,15 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// the list provides option to easily implement "isHttpMethod" guard
|
||||
const httpVerbs = ['get', 'post', 'put', 'delete', 'patch', 'options',
|
||||
'head', 'checkout', 'copy', 'lock', 'merge', 'mkactivity', 'mkcol',
|
||||
'move', 'm-search', 'notify', 'purge', 'report', 'search', 'subscribe',
|
||||
'trace', 'unlock','unsubscribe'] as const;
|
||||
/**
|
||||
* Strings that can be used as HTTP verbs (e.g. in requests)
|
||||
* Strings that can be used as HTTP verbs (e.g. in requests): 'get' | 'post' | 'put' | 'delete' etc.
|
||||
*/
|
||||
export type HTTPVerb = 'all' |
|
||||
'get' |
|
||||
'post' |
|
||||
'put' |
|
||||
'delete' |
|
||||
'patch' |
|
||||
'options' |
|
||||
'head' |
|
||||
'checkout' |
|
||||
'copy' |
|
||||
'lock' |
|
||||
'merge' |
|
||||
'mkactivity' |
|
||||
'mkcol' |
|
||||
'move' |
|
||||
'm-search' |
|
||||
'notify' |
|
||||
'purge' |
|
||||
'report' |
|
||||
'search' |
|
||||
'subscribe' |
|
||||
'trace' |
|
||||
'unlock' |
|
||||
'unsubscribe';
|
||||
export type HTTPVerb = typeof httpVerbs[number];
|
||||
|
||||
/**
|
||||
* Provides information if a text (representing a method) is an HTTP verb
|
||||
@@ -47,5 +29,5 @@ export type HTTPVerb = 'all' |
|
||||
* @param method A text (representing a method) to check
|
||||
*/
|
||||
export function isHttpMethod(method: string): method is HTTPVerb {
|
||||
return ['get', 'post', 'put'].indexOf(method) > -1;
|
||||
return (httpVerbs as unknown as string[]).indexOf(method) > -1;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export function createRoute<REQUESTTYPE, RETURNTYPE>(
|
||||
// the given type has no index signature so we have to cast to get the IRouteHandler when a HTTP method is given
|
||||
const route = router.route(routeClass.urlFragment);
|
||||
|
||||
// get route parameters (path parameters)
|
||||
// get route parameters (path parameters) TODO: DELETE as not used
|
||||
if (Array.isArray(routeClass.obligatoryParameters) && routeClass.obligatoryParameters.length > 0) {
|
||||
routeClass.obligatoryParameters.forEach((parameterName) => {
|
||||
router.param(parameterName, async (req, _res, next, parameterValue: string) => {
|
||||
@@ -101,7 +101,7 @@ export function createRoute<REQUESTTYPE, RETURNTYPE>(
|
||||
isTestEnvironment,
|
||||
);
|
||||
// The validation error is not caused by faulty user input, but through an error that originates somewhere in
|
||||
// the backend, therefor we use this "stacked" error.
|
||||
// the backend, therefore we use this "stacked" error.
|
||||
const internalServerError = new SCInternalServerErrorResponse(
|
||||
validationError,
|
||||
isTestEnvironment,
|
||||
|
||||
Reference in New Issue
Block a user