eslint: add no-floating-promises

This commit is contained in:
Alice Gaudon 2020-10-01 14:01:35 +02:00
parent e37184e5ee
commit a98c06fa92
2 changed files with 17 additions and 19 deletions

View File

@ -81,7 +81,8 @@
{
"accessibility": "explicit"
}
]
],
"@typescript-eslint/no-floating-promises": "error"
},
"ignorePatterns": [
"jest.config.js",
@ -106,4 +107,4 @@
}
}
]
}
}

View File

@ -39,21 +39,19 @@ describe('Test CSRF protection', () => {
test('no csrf token should be in session at first', (done) => {
const agent = supertest(app.getExpressApp());
agent.post('/')
.expect(401, (err, res) => {
if (err) return done(err);
.expect(401)
.then(res => {
expect(res.text).toContain(`You weren't assigned any CSRF token.`);
cookies = res.get('Set-Cookie');
agent.get('/')
.set('Cookie', cookies)
.expect(200, (err, res) => {
if (err) return done(err);
.expect(200)
.then(res => {
csrf = res.text;
done();
});
});
}).catch(done.fail);
}).catch(done.fail);
});
test('sending no csrf token should fail', (done) => {
@ -63,12 +61,10 @@ describe('Test CSRF protection', () => {
agent.post('/')
.set('Cookie', cookies)
.expect(401)
.end((err, res) => {
if (err) return done(err);
.then((res) => {
expect(res.text).toContain(`You didn't provide any CSRF token.`);
done();
});
}).catch(done.fail);
});
test('sending an invalid csrf token should fail', (done) => {
@ -79,12 +75,11 @@ describe('Test CSRF protection', () => {
.set('Cookie', cookies)
.set('Content-Type', 'application/json')
.send({csrf: 'not_a_valid_csrf'})
.expect(401, (err, res) => {
if (err) return done(err);
.expect(401)
.then(res => {
expect(res.text).toContain(`Tokens don't match.`);
done();
});
}).catch(done.fail);
});
test('sending a valid csrf token should success', (done) => {
@ -95,6 +90,8 @@ describe('Test CSRF protection', () => {
.set('Cookie', cookies)
.set('Content-Type', 'application/json')
.send({csrf: csrf})
.expect(200, done);
.expect(200)
.then(() => done())
.catch(done.fail);
});
});