UNPKG

2.69 kBJavaScriptView Raw
1// Jasmine test to check history
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);
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 history", function (done) {
49 var state = CodeGradX.getCurrentState();
50 function faildone (reason) {
51 state.debug(reason).show();
52 fail(reason);
53 done();
54 }
55 expect(campaign0 instanceof CodeGradX.Campaign).toBeTruthy();
56 campaign0.getJobs().then(function (jobs) {
57 //console.log(jobs);
58 expect(jobs.length).toBeGreaterThan(2);
59 done();
60 }, faildone);
61 }, 10*1000); // 10 seconds
62
63 it("should get skills", function (done) {
64 var state = CodeGradX.getCurrentState();
65 function faildone (reason) {
66 state.debug(reason).show();
67 fail(reason);
68 done();
69 }
70 expect(campaign0 instanceof CodeGradX.Campaign).toBeTruthy();
71 campaign0.getSkills().then(function (js) {
72 //console.log(js);
73 expect(js).toBeDefined();
74 expect(js.you).toBeDefined();
75 expect(js.you.skill).toBeDefined();
76 // Bad tests since these figures may evolve!
77 expect(js.you.personId).toBe(45);
78 expect(_.isObject(js.others)).toBeTruthy();
79 expect(js.others).toBeDefined();
80 expect(js.others[1]).toBe(5); //may evolve!
81 expect(js.others[2]).toBe(5); //may evolve!
82 done();
83 }, faildone);
84 }, 30*1000); // 15 seconds
85
86});