1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var CodeGradX = require('../codegradxlib.js');
|
7 | var authData = require('./auth1-data.json');
|
8 |
|
9 | describe('CodeGradX', function () {
|
10 | it('should be loaded', function () {
|
11 | expect(CodeGradX).toBeDefined();
|
12 | });
|
13 |
|
14 | it('should send authentication request', function (done) {
|
15 | var state = new CodeGradX.State();
|
16 | function faildone (reason) {
|
17 | state.debug('faildone', reason).show();
|
18 | fail(reason);
|
19 | done();
|
20 | }
|
21 | state.sendAXServer('x', {
|
22 | path: '/direct/check',
|
23 | method: 'POST',
|
24 | headers: {
|
25 | 'Accept': 'application/json',
|
26 | 'Content-Type': 'application/x-www-form-urlencoded'
|
27 | },
|
28 | entity: authData
|
29 | }).then(function (response) {
|
30 |
|
31 | expect(response.status).toBeDefined();
|
32 | expect(response.status.code).toBe(200);
|
33 | expect(response.headers['Set-Cookie']).toBeDefined();
|
34 | expect(response.entity.kind).toBe('authenticationAnswer');
|
35 |
|
36 | expect(state.currentCookie).toBeDefined();
|
37 | expect(state.currentCookie.length).toBeGreaterThan(0);
|
38 | state.currentUser = new CodeGradX.User(response.entity);
|
39 | expect(state.currentUser.lastname).toBe('FW4EX');
|
40 | expect(CodeGradX.getCurrentState()).toBe(state);
|
41 | state.sendAXServer('x', {
|
42 | path: '/',
|
43 | method: 'GET'
|
44 | }).then(function (response) {
|
45 |
|
46 |
|
47 | expect(response.raw.request._header).toMatch(/\r\nCookie: u=U/);
|
48 | expect(response.entity.kind).toBe('authenticationAnswer');
|
49 | done();
|
50 | }, faildone);
|
51 | }, faildone);
|
52 | }, 10*1000);
|
53 |
|
54 | it('again with getAuthenticatedUser', function (done) {
|
55 | var state = new CodeGradX.State();
|
56 | function faildone (reason) {
|
57 | state.debug(reason).show();
|
58 | fail(reason);
|
59 | done();
|
60 | }
|
61 | state.getAuthenticatedUser(authData.login, authData.password)
|
62 | .then(function (user) {
|
63 |
|
64 | expect(user).toBeDefined();
|
65 | expect(user.lastname).toBe('FW4EX');
|
66 | expect(user).toBe(state.currentUser);
|
67 | done();
|
68 | }, faildone);
|
69 | });
|
70 |
|
71 | });
|