-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathCLI.spec.js
More file actions
85 lines (76 loc) · 2.61 KB
/
Copy pathCLI.spec.js
File metadata and controls
85 lines (76 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var configuration = require("./config.json");
var Parse = require("parse/node");
var apps = configuration.applications;
var configLoader = require("../cli");
describe('CLI configuration loading', () => {
it('should load a JSON from arguments', done => {
var config = configLoader.loadFromCommandLine(["--config", "./spec/config.json"]);
expect(config).not.toBe(undefined);
expect(config.appId).toBe("123456");
done();
});
it('should throw when json does not exist', done => {
function load() {
return configLoader.loadFromCommandLine(["--config", "./spec/bar.json"]);
}
expect(load).toThrow();
done();
});
it('should throw when json is missing', done => {
function load() {
return configLoader.loadFromCommandLine(["--config"]);
}
expect(load).toThrow("Please specify the configuration file (json)");
done();
});
it('should retun nothing when nothing is specified', done => {
var config = configLoader.loadFromCommandLine();
expect(config).toBe(undefined);
done();
});
it('should support more arguments', done => {
var config = configLoader.loadFromCommandLine(["--some","--config", "./spec/config.json", "--other"]);
expect(config).not.toBe(undefined);
expect(config.appId).toBe("123456");
done();
});
it('should load from environment', done => {
var env = {
PARSE_SERVER_DATABASE_URI: "",
PARSE_SERVER_CLOUD_CODE_MAIN: "",
PARSE_SERVER_COLLECTION_PREFIX: "",
PARSE_SERVER_APPLICATION_ID: "",
PARSE_SERVER_CLIENT_KEY: "",
PARSE_SERVER_REST_API_KEY: "",
PARSE_SERVER_DOTNET_KEY: "",
PARSE_SERVER_JAVASCRIPT_KEY: "",
PARSE_SERVER_DOTNET_KEY: "",
PARSE_SERVER_MASTER_KEY: "",
PARSE_SERVER_FILE_KEY: "",
PARSE_SERVER_FACEBOOK_APP_IDS: "hello,world"
}
var config = configLoader.loadFromEnvironment(env);
expect(config).not.toBe(undefined);
expect(Object.keys(config).length).toBe(Object.keys(env).length);
expect(config.facebookAppIds.length).toBe(2);
expect(config.facebookAppIds).toContain("hello");
expect(config.facebookAppIds).toContain("world");
done();
});
it('should load from environment options', done => {
var env = {
PARSE_SERVER_OPTIONS: require("fs").readFileSync("./spec/config.json")
}
var config = configLoader.loadFromEnvironment(env);
expect(config).not.toBe(undefined);
expect(config.appId).toBe("123456");
done();
});
it('should load empty configuration options', done => {
var config = configLoader();
expect(config).not.toBe(undefined);
expect(config).not.toBe({});
expect(config.appId).toBe(undefined);
done();
});
});