/
MaxiEnergy
/
Task2-DevSecOps
Обзор
Документация
Войти
/
MaxiEnergy
/
Task2-DevSecOps
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/app.spec.js
45 строк
1 KB
coursar
initial commit
04 фев 2021, 10:31
Не верифицирован
04 фев 2021, 10:31
b0c64b4
Код
Авторство
О чём код?
const supertest = require('supertest'); jest.setTimeout(60 * 1000); describe('transactions app', () => { const request = supertest(process.env.API_URL || 'http://localhost:9999'); beforeAll(async () => { for (let i = 0; i < 5; i++) { try { console.log(`check health: ${i}`); await request.get('/health').expect(200); console.log('successfully connected'); return; } catch (e) { console.log(e); await new Promise(resolve => setTimeout(() => resolve(), 5 * 1000)); } } }); test('should pass common path', async () => { const {body: {token}} = await request.post('/auth') .set('content-type', 'application/json') .send({ login: 'vasya', password: 'secret', }) .expect(200); expect(token).toBeDefined(); const {body: {transactions}} = await request.get('/private/transactions') .set('content-type', 'application/json') .set('authorization', `Bearer ${token}`) .send() .expect(200); expect(transactions).toHaveLength(3); }); test('should prevent unauthorized access', async () => { await request.get('/private/transactions') .set('content-type', 'application/json') .send() .expect(401); }); });