UNPKG

1.95 kBJavaScriptView Raw
1//
2
3var CodeGradX = require('codegradxagent');
4var Agent = require('../codegradxvmauthor.js');
5
6describe("CodeGradXvmauthor", function () {
7 it("should be loaded", function () {
8 expect(Agent).toBeDefined();
9 var agent = new CodeGradX.Agent();
10 expect(agent).toBeDefined();
11 });
12
13 function make_faildone (done) {
14 return function faildone (reason) {
15 agent.state.debug(reason).show();
16 fail(reason);
17 done();
18 };
19 }
20
21 it("displays help", function (done) {
22 var agent = new CodeGradX.Agent();
23 var faildone = make_faildone(done);
24 spyOn(agent, "usage");
25 agent.process([
26 "-h"
27 ]).then(faildone, function (reason) {
28 expect(agent.usage).toHaveBeenCalled();
29 done();
30 });
31 });
32
33 it("handles unknown option", function (done) {
34 var agent = new CodeGradX.Agent();
35 var faildone = make_faildone(done);
36 spyOn(agent, "usage");
37 agent.process([
38 "--unknownOption"
39 ]).then(faildone, function (reason) {
40 expect(agent.usage).toHaveBeenCalled();
41 done();
42 });
43 });
44
45 it("handles missing argument for option", function (done) {
46 var agent = new CodeGradX.Agent();
47 var faildone = make_faildone(done);
48 spyOn(agent, "usage");
49 agent.process([
50 "--counter"
51 ]).then(faildone, function (reason) {
52 expect(agent.usage).toHaveBeenCalled();
53 done();
54 });
55 });
56
57 it("cannot read absent credentials", function (done) {
58 var agent = new CodeGradX.Agent();
59 var faildone = make_faildone(done);
60 agent.process([
61 "--credentials", "spec/absentCredentials.json"
62 ]).then(faildone, function (reason) {
63 expect(agent.credentials).not.toBeDefined();
64 done();
65 });
66 });
67
68});