Completed
Pull Request — master (#29)
by Jean
01:16
created

test-codingame-api.js ➔ ... ➔ after   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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