Total Complexity | 6 |
Complexity/F | 1 |
Lines of Code | 42 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import chai from 'chai'; |
||
2 | import chaiaspromised from 'chai-as-promised'; |
||
3 | import nock from 'nock'; |
||
4 | |||
5 | import cgapi from '../src/codingame-api.js'; |
||
6 | |||
7 | let expect = chai.expect; |
||
8 | chai.use(chaiaspromised); |
||
9 | |||
10 | describe(`[module] codingame-api`, function() { |
||
11 | describe(`[method] login`, function() { |
||
12 | let credentialsok = { |
||
13 | "username": `me`, |
||
14 | "password": `p4ssw0rd` |
||
15 | }; |
||
16 | let credentialsnotok = { |
||
17 | "username": `me`, |
||
18 | "password": `password` |
||
19 | }; |
||
20 | let response = { |
||
21 | "success": true |
||
22 | }; |
||
23 | before(function() { |
||
24 | nock(`https://www.codingame.com`) |
||
25 | .post(`/services/CodingamerRemoteService/loginSiteV2`, [credentialsok.username, credentialsok.password, true]) |
||
26 | .reply(200, response) |
||
27 | .post(`/services/CodingamerRemoteService/loginSiteV2`, [credentialsnotok.username, credentialsnotok.password, true]) |
||
28 | .reply(403); |
||
29 | }); |
||
30 | after(function() { |
||
31 | nock.cleanAll(); |
||
32 | }) |
||
33 | it(`should resolve with correct username and password`, function() { |
||
34 | let login = cgapi.login(credentialsok.username, credentialsok.password); |
||
35 | return expect(login).to.eventually.be.fullfilled; |
||
36 | }); |
||
37 | it(`should reject with incorrect password`, function() { |
||
38 | let login = cgapi.login(credentialsnotok.username, credentialsnotok.password); |
||
39 | return expect(login).to.eventually.be.rejected; |
||
40 | }); |
||
41 | }); |
||
42 | }); |
||
43 |