1 |
|
2 |
|
3 | var CodeGradX = require('../codegradxlib.js');
|
4 | var xml2js = require('xml2js').parseString;
|
5 |
|
6 | describe('CodeGradX', function () {
|
7 |
|
8 | it('should be loaded', function () {
|
9 | expect(CodeGradX).toBeDefined();
|
10 | });
|
11 |
|
12 | it('should send failing authentication request', function (done) {
|
13 | var state = new CodeGradX.State();
|
14 | function faildone (reason) {
|
15 | state.log.show();
|
16 | fail(reason);
|
17 | done();
|
18 | }
|
19 | var promise1 = state.checkServers('x');
|
20 | promise1.then(function (descriptions) {
|
21 |
|
22 |
|
23 | expect(descriptions.next).toBeUndefined();
|
24 | var promise2 = state.sendAXServer('x', {
|
25 | path: '/direct/check',
|
26 | method: 'POST',
|
27 | headers: {
|
28 | 'Accept': 'application/json, text/xml',
|
29 | 'Content-Type': 'application/x-www-form-urlencoded'
|
30 | },
|
31 | entity: {
|
32 | login: 'foo',
|
33 | password: 'xyzzy'
|
34 | }
|
35 | }).then(faildone).catch(function (reason) {
|
36 | done();
|
37 | });
|
38 | }, faildone);
|
39 | }, 10*1000);
|
40 |
|
41 | it('should get public list of exercises', function (done) {
|
42 | var state = new CodeGradX.State();
|
43 | function faildone (reason) {
|
44 | fail(reason);
|
45 | done();
|
46 | }
|
47 | var promise1 = state.checkServers('e');
|
48 | promise1.then(function (descriptions) {
|
49 | var promise2 = state.sendESServer('e', {
|
50 | path: '/path/insta2',
|
51 | headers: {
|
52 | 'Accept': 'application/json'
|
53 | }
|
54 | }).then(function (response) {
|
55 |
|
56 | expect(response.status.code).toBe(200);
|
57 | var es = new CodeGradX.ExercisesSet(response.entity);
|
58 | expect(es).toBeDefined();
|
59 |
|
60 | expect(es.title).not.toBeDefined();
|
61 | expect(es.exercises.length).toBeGreaterThan(1);
|
62 |
|
63 | expect(es.exercises[0].title).toBe('Javascript');
|
64 | expect(es.exercises[0].exercises[0].nickname).toBe('min3');
|
65 | done();
|
66 | }, faildone);
|
67 | }, faildone);
|
68 | });
|
69 |
|
70 | it('again with implicit checkServers', function (done) {
|
71 | var state = new CodeGradX.State();
|
72 | function faildone (reason) {
|
73 | fail(reason);
|
74 | done();
|
75 | }
|
76 | state.sendESServer('e', {
|
77 | path: '/path/insta2',
|
78 | headers: {
|
79 | 'Accept': 'application/json'
|
80 | }
|
81 | }).then(function (response) {
|
82 |
|
83 | expect(response.status.code).toBe(200);
|
84 | var es = new CodeGradX.ExercisesSet(response.entity);
|
85 | expect(es).toBeDefined();
|
86 |
|
87 | expect(es.title).not.toBeDefined();
|
88 | expect(es.exercises.length).toBeGreaterThan(1);
|
89 |
|
90 | expect(es.exercises[0].title).toBe('Javascript');
|
91 | expect(es.exercises[0].exercises[0].nickname).toBe('min3');
|
92 | done();
|
93 | }, faildone);
|
94 | });
|
95 |
|
96 | it("should get a public job report", function (done) {
|
97 | var state = new CodeGradX.State();
|
98 | function faildone (reason) {
|
99 | state.log.show();
|
100 | fail(reason);
|
101 | done();
|
102 | }
|
103 | var promise1 = state.checkServers('s');
|
104 | promise1.then(function (responses) {
|
105 | var promise2 = state.sendESServer('s', {
|
106 | path: "/s/D/B/F/6/0/8/9/8/8/A/0/2/1/1/E/5/8/D/7/4/A/9/8/8/7/0/A/0/6/C/9/0/DBF60898-8A02-11E5-8D74-A98870A06C90.xml"
|
107 | }).then(function (response) {
|
108 |
|
109 |
|
110 | expect(response.status.code).toBe(200);
|
111 | xml2js(response.entity, function (err, result) {
|
112 | if ( err ) {
|
113 | fail(err);
|
114 | } else {
|
115 |
|
116 | expect(result.fw4ex.jobStudentReport).toBeDefined();
|
117 | }
|
118 | });
|
119 | done();
|
120 | }, faildone);
|
121 | }, faildone);
|
122 | }, 10*1000);
|
123 |
|
124 | it("again with implicit checkServers", function (done) {
|
125 | var state = new CodeGradX.State();
|
126 | function faildone (reason) {
|
127 | fail(reason);
|
128 | done();
|
129 | }
|
130 | state.sendESServer('s', {
|
131 | path: '/s/D/8/F/A/1/C/4/E/8/7/E/7/1/1/D/D/B/7/3/8/2/E/2/7/1/B/8/B/9/4/E/0/D8FA1C4E-87E7-11DD-B738-2E271B8B94E0.xml'
|
132 | }).then(function (response) {
|
133 |
|
134 |
|
135 | expect(response.status.code).toBe(200);
|
136 | xml2js(response.entity, function (err, result) {
|
137 | if ( err ) {
|
138 | fail(err);
|
139 | } else {
|
140 |
|
141 | expect(result.fw4ex.jobStudentReport).toBeDefined();
|
142 | }
|
143 | });
|
144 | done();
|
145 | }, faildone);
|
146 | });
|
147 |
|
148 | it("should get a public job report repeatedly", function (done) {
|
149 | var state = new CodeGradX.State();
|
150 | function faildone (reason) {
|
151 | fail(reason);
|
152 | done();
|
153 | }
|
154 | state.sendRepeatedlyESServer('s', {
|
155 | step: 1,
|
156 | attempts: 5
|
157 | }, {
|
158 | path: '/s/D/8/F/A/1/C/4/E/8/7/E/7/1/1/D/D/B/7/3/8/2/E/2/7/1/B/8/B/9/4/E/0/D8FA1C4E-87E7-11DD-B738-2E271B8B94E0.xml'
|
159 | }).then(function (response) {
|
160 |
|
161 |
|
162 | expect(response.status.code).toBe(200);
|
163 | xml2js(response.entity, function (err, result) {
|
164 | if ( err ) {
|
165 | fail(err);
|
166 | } else {
|
167 |
|
168 | expect(result.fw4ex.jobStudentReport).toBeDefined();
|
169 | }
|
170 | });
|
171 | done();
|
172 | }, faildone);
|
173 | });
|
174 |
|
175 | });
|