mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
Resolve "Transition to ESLint"
This commit is contained in:
committed by
Rainer Killinger
parent
ca1d2444e0
commit
418ba67d15
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -17,7 +18,8 @@ import {
|
||||
SCInternalServerErrorResponse,
|
||||
SCMethodNotAllowedErrorResponse,
|
||||
SCRoute,
|
||||
SCRouteHttpVerbs, SCValidationErrorResponse,
|
||||
SCRouteHttpVerbs,
|
||||
SCValidationErrorResponse,
|
||||
} from '@openstapps/core';
|
||||
import * as bodyParser from 'body-parser';
|
||||
import sinon from 'sinon';
|
||||
@@ -31,15 +33,16 @@ import {Logger} from '@openstapps/logger';
|
||||
import {DEFAULT_TEST_TIMEOUT} from '../common';
|
||||
|
||||
interface ReturnType {
|
||||
foo: boolean;
|
||||
foo: boolean;
|
||||
}
|
||||
|
||||
describe('Create route', async function () {
|
||||
let routeClass: SCRoute;
|
||||
let handler: (
|
||||
validatedBody: any,
|
||||
app: Application, params?: { [parameterName: string]: string; },
|
||||
) => Promise<ReturnType>;
|
||||
validatedBody: any,
|
||||
app: Application,
|
||||
parameters?: {[parameterName: string]: string},
|
||||
) => Promise<ReturnType>;
|
||||
let app: Express;
|
||||
const statusCodeSuccess = 222;
|
||||
const bodySuccess = {foo: true};
|
||||
@@ -75,10 +78,12 @@ describe('Create route', async function () {
|
||||
|
||||
it('should complain (throw an error) if used method is other than defined in the route creation', async function () {
|
||||
const methodNotAllowedError = new SCMethodNotAllowedErrorResponse();
|
||||
// @ts-ignore
|
||||
sandbox.stub(validator, 'validate').returns({errors: []})
|
||||
// @ts-expect-error not assignable
|
||||
sandbox.stub(validator, 'validate').returns({errors: []});
|
||||
let error: any = {};
|
||||
sandbox.stub(Logger, 'warn').callsFake((err) => { error = err });
|
||||
sandbox.stub(Logger, 'warn').callsFake(error_ => {
|
||||
error = error_;
|
||||
});
|
||||
const router = createRoute<any, any>(routeClass, handler);
|
||||
await app.use(router);
|
||||
|
||||
@@ -92,14 +97,12 @@ describe('Create route', async function () {
|
||||
});
|
||||
|
||||
it('should provide a route which returns handler response and success code', async function () {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error not assignable
|
||||
sandbox.stub(validator, 'validate').returns({errors: []});
|
||||
const router = createRoute<any, any>(routeClass, handler);
|
||||
app.use(router);
|
||||
|
||||
const response = await supertest(app)
|
||||
.post(routeClass.urlPath)
|
||||
.send();
|
||||
const response = await supertest(app).post(routeClass.urlPath).send();
|
||||
|
||||
expect(response.status).to.be.equal(statusCodeSuccess);
|
||||
expect(response.body).to.be.deep.equal(bodySuccess);
|
||||
@@ -112,7 +115,7 @@ describe('Create route', async function () {
|
||||
app.use(router);
|
||||
const startApp = supertest(app);
|
||||
const validatorStub = sandbox.stub(validator, 'validate');
|
||||
// @ts-ignore
|
||||
// @ts-expect-error not assignable
|
||||
validatorStub.withArgs(body, routeClass.requestBodyName).returns({errors: [new Error('Foo Error')]});
|
||||
|
||||
const response = await startApp
|
||||
@@ -128,14 +131,14 @@ describe('Create route', async function () {
|
||||
const router = createRoute<any, any>(routeClass, handler);
|
||||
await app.use(router);
|
||||
const startApp = supertest(app);
|
||||
// @ts-ignore
|
||||
const validatorStub = sandbox.stub(validator, 'validate').returns({errors:[]});
|
||||
// @ts-ignore
|
||||
validatorStub.withArgs(bodySuccess, routeClass.responseBodyName).returns({errors: [new Error('Foo Error')]});
|
||||
// @ts-expect-error not assignable
|
||||
const validatorStub = sandbox.stub(validator, 'validate').returns({errors: []});
|
||||
validatorStub
|
||||
.withArgs(bodySuccess, routeClass.responseBodyName)
|
||||
// @ts-expect-error not assignable
|
||||
.returns({errors: [new Error('Foo Error')]});
|
||||
|
||||
const response = await startApp
|
||||
.post(routeClass.urlPath)
|
||||
.send();
|
||||
const response = await startApp.post(routeClass.urlPath).send();
|
||||
|
||||
expect(response.status).to.be.equal(internalServerError.statusCode);
|
||||
});
|
||||
@@ -143,8 +146,11 @@ describe('Create route', async function () {
|
||||
it('should return internal server error if error response not allowed', async function () {
|
||||
class FooErrorResponse {
|
||||
statusCode: number;
|
||||
|
||||
name: string;
|
||||
|
||||
message: string;
|
||||
|
||||
constructor(statusCode: number, name: string, message: string) {
|
||||
this.statusCode = statusCode;
|
||||
this.name = name;
|
||||
@@ -153,6 +159,7 @@ describe('Create route', async function () {
|
||||
}
|
||||
class BarErrorResponse {
|
||||
statusCode: number;
|
||||
|
||||
constructor(statusCode: number) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
@@ -170,12 +177,10 @@ describe('Create route', async function () {
|
||||
await app.use(router);
|
||||
const startApp = supertest(app);
|
||||
|
||||
// @ts-ignore
|
||||
sandbox.stub(validator, 'validate').returns({errors:[]});
|
||||
// @ts-expect-error not assignable
|
||||
sandbox.stub(validator, 'validate').returns({errors: []});
|
||||
|
||||
const response = await startApp
|
||||
.post(routeClass.urlPath)
|
||||
.send();
|
||||
const response = await startApp.post(routeClass.urlPath).send();
|
||||
|
||||
expect(response.status).to.be.equal(internalServerError.statusCode);
|
||||
});
|
||||
@@ -183,8 +188,11 @@ describe('Create route', async function () {
|
||||
it('should return the exact error if error response is allowed', async function () {
|
||||
class FooErrorResponse {
|
||||
statusCode: number;
|
||||
|
||||
name: string;
|
||||
|
||||
message: string;
|
||||
|
||||
constructor(statusCode: number, name: string, message: string) {
|
||||
this.statusCode = statusCode;
|
||||
this.name = name;
|
||||
@@ -205,12 +213,10 @@ describe('Create route', async function () {
|
||||
await app.use(router);
|
||||
const startApp = supertest(app);
|
||||
|
||||
// @ts-ignore
|
||||
sandbox.stub(validator, 'validate').returns({errors:[]});
|
||||
// @ts-expect-error not assignable
|
||||
sandbox.stub(validator, 'validate').returns({errors: []});
|
||||
|
||||
const response = await startApp
|
||||
.post(routeClass.urlPath)
|
||||
.send();
|
||||
const response = await startApp.post(routeClass.urlPath).send();
|
||||
|
||||
expect(response.status).to.be.equal(fooErrorResponse.statusCode);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user