Skip to content

Commit

Permalink
fix: convert simple-password-provider.test.js to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarconr committed Jan 26, 2022
1 parent 50364cd commit 332b94d
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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();
app.use(express.json());
const userService = () => {};
const ctr = new PasswordProvider({ getLogger }, { userService });

//@ts-ignore
app.use('/auth/simple', ctr.router);

const res = await request(app)
Expand All @@ -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();
});
Expand All @@ -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)
Expand All @@ -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();
});
Expand All @@ -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);
});

0 comments on commit 332b94d

Please sign in to comment.