mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: convert simple-password-provider.test.js to ts
This commit is contained in:
parent
50364cd298
commit
332b94d209
@ -1,9 +1,9 @@
|
|||||||
const request = require('supertest');
|
import request from 'supertest';
|
||||||
const express = require('express');
|
import express from 'express';
|
||||||
const User = require('../../types/user');
|
import User from '../../types/user';
|
||||||
const PasswordProvider = require('./simple-password-provider');
|
import PasswordProvider from './simple-password-provider';
|
||||||
|
import PasswordMismatchError from '../../error/password-mismatch';
|
||||||
const getLogger = () => ({ info: () => {}, error: () => {} });
|
import getLogger from '../../../test/fixtures/no-logger';
|
||||||
|
|
||||||
test('Should require password', async () => {
|
test('Should require password', async () => {
|
||||||
const app = express();
|
const app = express();
|
||||||
@ -11,6 +11,7 @@ test('Should require password', async () => {
|
|||||||
const userService = () => {};
|
const userService = () => {};
|
||||||
const ctr = new PasswordProvider({ getLogger }, { userService });
|
const ctr = new PasswordProvider({ getLogger }, { userService });
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
app.use('/auth/simple', ctr.router);
|
app.use('/auth/simple', ctr.router);
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
@ -28,6 +29,7 @@ test('Should login user', async () => {
|
|||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
|
//@ts-ignore
|
||||||
req.session = {};
|
req.session = {};
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -41,6 +43,7 @@ test('Should login user', async () => {
|
|||||||
};
|
};
|
||||||
const ctr = new PasswordProvider({ getLogger }, { userService });
|
const ctr = new PasswordProvider({ getLogger }, { userService });
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
app.use('/auth/simple', ctr.router);
|
app.use('/auth/simple', ctr.router);
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
@ -59,6 +62,7 @@ test('Should not login user with wrong password', async () => {
|
|||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
|
//@ts-ignore
|
||||||
req.session = {};
|
req.session = {};
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -67,16 +71,17 @@ test('Should not login user with wrong password', async () => {
|
|||||||
if (u === username && p === password) {
|
if (u === username && p === password) {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
throw new Error('Wrong password');
|
throw new PasswordMismatchError();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const ctr = new PasswordProvider({ getLogger }, { userService });
|
const ctr = new PasswordProvider({ getLogger }, { userService });
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
app.use('/auth/simple', ctr.router);
|
app.use('/auth/simple', ctr.router);
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post('/auth/simple/login')
|
.post('/auth/simple/login')
|
||||||
.send({ username, password: 'not-correct' });
|
.send({ username, password: 'not-correct' });
|
||||||
|
|
||||||
expect(401).toBe(res.status);
|
expect(res.status).toBe(401);
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user