UNPKG

2.23 kBJavaScriptView Raw
1// Jasmine test to check progress
2// requires file ./auth-data.json with login and password (not under git!)
3
4var CodeGradX = require('../codegradxlib.js');
5var authData = require('./auth1-data.json'); // lambda student
6var _ = require('lodash');
7
8describe('CodeGradX', function () {
9
10 it('should be loaded', function (done) {
11 expect(CodeGradX).toBeDefined();
12 var state = new CodeGradX.State();
13 function faildone (reason) {
14 state.debug(reason).show();
15 fail(reason);
16 done();
17 }
18 state.getAuthenticatedUser(authData.login, authData.password)
19 .then(function (user) {
20 expect(user).toBeDefined();
21 expect(user).toBe(state.currentUser);
22 done();
23 }, faildone);
24 });
25
26 var campaign0;
27
28 it("should get campaign free", function (done) {
29 var state = CodeGradX.getCurrentState();
30 function faildone (reason) {
31 state.debug(reason).show();
32 fail(reason);
33 done();
34 }
35 expect(state.currentUser instanceof CodeGradX.User).toBeTruthy();
36 state.currentUser.getCampaign('free').then(function (campaign) {
37 expect(campaign instanceof CodeGradX.Campaign).toBeTruthy();
38 //console.log(campaign);//DEBUG
39 campaign0 = campaign;
40 campaign.getExercisesSet().then(function (es) {
41 expect(es instanceof CodeGradX.ExercisesSet).toBeTruthy();
42 expect(es).toBe(campaign.exercisesSet);
43 done();
44 }, faildone);
45 }, faildone);
46 });
47
48 it("should get progress", function (done) {
49 var state = CodeGradX.getCurrentState();
50 function faildone (reason) {
51 state.debug(reason).show();
52 fail(reason);
53 done();
54 }
55 expect(state.currentUser instanceof CodeGradX.User).toBeTruthy();
56 state.currentUser.getProgress(campaign0).then(function (user) {
57 expect(user.results.length).toBeGreaterThan(0);
58 console.log(user.results);//DEBUG
59 expect(user.results[0].name).toBe('com.paracamplus.li205.function.1');
60 expect(user.results[0].nickname).toBe('min');
61 expect(user.results[0].mark).toBe(1);
62 expect(user.badges.length).toBe(0);
63 done();
64 }, faildone);
65 }, 10*1000); // 10 seconds
66
67});