From 332b94d2097387168a4ce1047a99acf7696449cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 26 Jan 2022 22:44:26 +0100 Subject: [PATCH] fix: convert simple-password-provider.test.js to ts --- ...st.js => simple-password-provider.test.ts} | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) rename src/lib/routes/auth/{simple-password-provider.test.js => simple-password-provider.test.ts} (80%) diff --git a/src/lib/routes/auth/simple-password-provider.test.js b/src/lib/routes/auth/simple-password-provider.test.ts similarity index 80% rename from src/lib/routes/auth/simple-password-provider.test.js rename to src/lib/routes/auth/simple-password-provider.test.ts index 01fc04bab9..73a3c6ddb5 100644 --- a/src/lib/routes/auth/simple-password-provider.test.js +++ b/src/lib/routes/auth/simple-password-provider.test.ts @@ -1,9 +1,9 @@ -const request = require('supertest'); -const express = require('express'); -const User = require('../../types/user'); -const PasswordProvider = require('./simple-password-provider'); - -const getLogger = () => ({ info: () => {}, error: () => {} }); +import request from 'supertest'; +import express from 'express'; +import User from '../../types/user'; +import PasswordProvider from './simple-password-provider'; +import PasswordMismatchError from '../../error/password-mismatch'; +import getLogger from '../../../test/fixtures/no-logger'; test('Should require password', async () => { const app = express(); @@ -11,6 +11,7 @@ test('Should require password', async () => { const userService = () => {}; const ctr = new PasswordProvider({ getLogger }, { userService }); + //@ts-ignore app.use('/auth/simple', ctr.router); const res = await request(app) @@ -28,6 +29,7 @@ test('Should login user', async () => { const app = express(); app.use(express.json()); app.use((req, res, next) => { + //@ts-ignore req.session = {}; next(); }); @@ -41,6 +43,7 @@ test('Should login user', async () => { }; const ctr = new PasswordProvider({ getLogger }, { userService }); + //@ts-ignore app.use('/auth/simple', ctr.router); const res = await request(app) @@ -59,6 +62,7 @@ test('Should not login user with wrong password', async () => { const app = express(); app.use(express.json()); app.use((req, res, next) => { + //@ts-ignore req.session = {}; next(); }); @@ -67,16 +71,17 @@ test('Should not login user with wrong password', async () => { if (u === username && p === password) { return user; } - throw new Error('Wrong password'); + throw new PasswordMismatchError(); }, }; const ctr = new PasswordProvider({ getLogger }, { userService }); + //@ts-ignore app.use('/auth/simple', ctr.router); const res = await request(app) .post('/auth/simple/login') .send({ username, password: 'not-correct' }); - expect(401).toBe(res.status); + expect(res.status).toBe(401); });