@anmiles/google-api-wrapper 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +91 -0
- package/.gitlab-ci.yml +118 -0
- package/.vscode/settings.json +10 -0
- package/CHANGELOG.md +14 -0
- package/LICENSE.md +21 -0
- package/README.md +35 -0
- package/coverage.config.js +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/auth.d.ts +9 -0
- package/dist/lib/auth.js +27 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/data.d.ts +23 -0
- package/dist/lib/data.js +45 -0
- package/dist/lib/data.js.map +1 -0
- package/dist/lib/jsonLib.d.ts +14 -0
- package/dist/lib/jsonLib.js +48 -0
- package/dist/lib/jsonLib.js.map +1 -0
- package/dist/lib/logger.d.ts +12 -0
- package/dist/lib/logger.js +46 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/paths.d.ts +14 -0
- package/dist/lib/paths.js +42 -0
- package/dist/lib/paths.js.map +1 -0
- package/dist/lib/profiles.d.ts +10 -0
- package/dist/lib/profiles.js +34 -0
- package/dist/lib/profiles.js.map +1 -0
- package/dist/lib/secrets.d.ts +16 -0
- package/dist/lib/secrets.js +95 -0
- package/dist/lib/secrets.js.map +1 -0
- package/dist/lib/sleep.d.ts +6 -0
- package/dist/lib/sleep.js +11 -0
- package/dist/lib/sleep.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/secrets.d.ts +11 -0
- package/dist/types/secrets.js +3 -0
- package/dist/types/secrets.js.map +1 -0
- package/jest.config.js +22 -0
- package/package.json +50 -0
- package/src/index.ts +3 -0
- package/src/lib/__tests__/auth.test.ts +97 -0
- package/src/lib/__tests__/data.test.ts +154 -0
- package/src/lib/__tests__/jsonLib.test.ts +165 -0
- package/src/lib/__tests__/logger.test.ts +57 -0
- package/src/lib/__tests__/paths.test.ts +116 -0
- package/src/lib/__tests__/profiles.test.ts +117 -0
- package/src/lib/__tests__/secrets.test.ts +304 -0
- package/src/lib/__tests__/sleep.test.ts +17 -0
- package/src/lib/auth.ts +31 -0
- package/src/lib/data.ts +81 -0
- package/src/lib/jsonLib.ts +48 -0
- package/src/lib/logger.ts +21 -0
- package/src/lib/paths.ts +39 -0
- package/src/lib/profiles.ts +33 -0
- package/src/lib/secrets.ts +79 -0
- package/src/lib/sleep.ts +8 -0
- package/src/types/index.ts +1 -0
- package/src/types/secrets.ts +11 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import logger from '../logger';
|
|
3
|
+
import paths from '../paths';
|
|
4
|
+
|
|
5
|
+
import jsonLib from '../jsonLib';
|
|
6
|
+
const original = jest.requireActual('../jsonLib').default as typeof jsonLib;
|
|
7
|
+
jest.mock<typeof jsonLib>('../jsonLib', () => ({
|
|
8
|
+
readJSON : jest.fn().mockImplementation(() => json),
|
|
9
|
+
writeJSON : jest.fn(),
|
|
10
|
+
getJSON : jest.fn(),
|
|
11
|
+
getJSONAsync : jest.fn(),
|
|
12
|
+
checkJSON : jest.fn(),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
16
|
+
readFileSync : jest.fn().mockImplementation(() => jsonString),
|
|
17
|
+
writeFileSync : jest.fn(),
|
|
18
|
+
existsSync : jest.fn().mockImplementation(() => fileExists),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock<Partial<typeof logger>>('../logger', () => ({
|
|
22
|
+
error : jest.fn().mockImplementation((error) => {
|
|
23
|
+
throw error;
|
|
24
|
+
}) as jest.Mock<never, any>,
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
jest.mock<Partial<typeof paths>>('../paths', () => ({
|
|
28
|
+
ensureFile : jest.fn(),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
const filename = 'filename';
|
|
32
|
+
const json = { key : 'value' };
|
|
33
|
+
const jsonString = JSON.stringify(json, null, ' ');
|
|
34
|
+
const fallbackJSON = { fallbackKey : 'fallbackValue' };
|
|
35
|
+
|
|
36
|
+
const createCallback = jest.fn().mockReturnValue(fallbackJSON);
|
|
37
|
+
const createCallbackAsync = jest.fn().mockResolvedValue(fallbackJSON);
|
|
38
|
+
|
|
39
|
+
let fileExists: boolean;
|
|
40
|
+
|
|
41
|
+
describe('src/lib/jsonLib', () => {
|
|
42
|
+
describe('readJSON', () => {
|
|
43
|
+
it('should read specified file', () => {
|
|
44
|
+
original.readJSON(filename);
|
|
45
|
+
|
|
46
|
+
expect(fs.readFileSync).toBeCalledWith(filename);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should return parsed JSON', () => {
|
|
50
|
+
const result = original.readJSON(filename);
|
|
51
|
+
|
|
52
|
+
expect(result).toEqual(json);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('writeJSON', () => {
|
|
57
|
+
it('should write JSON into specified file', () => {
|
|
58
|
+
original.writeJSON(filename, json);
|
|
59
|
+
|
|
60
|
+
expect(fs.writeFileSync).toBeCalledWith(filename, jsonString);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('getJSON', () => {
|
|
65
|
+
it('should call readJSON if file exists', () => {
|
|
66
|
+
fileExists = true;
|
|
67
|
+
|
|
68
|
+
original.getJSON(filename, createCallback);
|
|
69
|
+
|
|
70
|
+
expect(jsonLib.readJSON).toBeCalledWith(filename);
|
|
71
|
+
expect(createCallback).not.toBeCalled();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should call createCallback if file not exists', () => {
|
|
75
|
+
fileExists = false;
|
|
76
|
+
|
|
77
|
+
original.getJSON(filename, createCallback);
|
|
78
|
+
|
|
79
|
+
expect(jsonLib.readJSON).not.toBeCalled();
|
|
80
|
+
expect(createCallback).toBeCalledWith();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should write fallback JSON back if file not exists', () => {
|
|
84
|
+
fileExists = false;
|
|
85
|
+
|
|
86
|
+
original.getJSON(filename, createCallback);
|
|
87
|
+
|
|
88
|
+
expect(jsonLib.checkJSON).toBeCalledWith(filename, fallbackJSON);
|
|
89
|
+
expect(paths.ensureFile).toBeCalledWith(filename);
|
|
90
|
+
expect(jsonLib.writeJSON).toBeCalledWith(filename, fallbackJSON);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should return JSON if file exists', () => {
|
|
94
|
+
fileExists = true;
|
|
95
|
+
|
|
96
|
+
const result = original.getJSON(filename, createCallback);
|
|
97
|
+
|
|
98
|
+
expect(result).toEqual(json);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should return fallback JSON if file not exists', () => {
|
|
102
|
+
fileExists = false;
|
|
103
|
+
|
|
104
|
+
const result = original.getJSON(filename, createCallback);
|
|
105
|
+
|
|
106
|
+
expect(result).toEqual(fallbackJSON);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('getJSONAsync', () => {
|
|
111
|
+
it('should call readJSON if file exists', async () => {
|
|
112
|
+
fileExists = true;
|
|
113
|
+
|
|
114
|
+
await original.getJSONAsync(filename, createCallbackAsync);
|
|
115
|
+
|
|
116
|
+
expect(jsonLib.readJSON).toBeCalledWith(filename);
|
|
117
|
+
expect(createCallbackAsync).not.toBeCalled();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should call createCallback if file not exists', async () => {
|
|
121
|
+
fileExists = false;
|
|
122
|
+
|
|
123
|
+
await original.getJSONAsync(filename, createCallbackAsync);
|
|
124
|
+
|
|
125
|
+
expect(jsonLib.readJSON).not.toBeCalled();
|
|
126
|
+
expect(createCallbackAsync).toBeCalledWith();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should write fallback JSON back if file not exists', async () => {
|
|
130
|
+
fileExists = false;
|
|
131
|
+
|
|
132
|
+
await original.getJSONAsync(filename, createCallbackAsync);
|
|
133
|
+
|
|
134
|
+
expect(jsonLib.checkJSON).toBeCalledWith(filename, fallbackJSON);
|
|
135
|
+
expect(jsonLib.writeJSON).toBeCalledWith(filename, fallbackJSON);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should return JSON if file exists', async () => {
|
|
139
|
+
fileExists = true;
|
|
140
|
+
|
|
141
|
+
const result = await original.getJSONAsync(filename, createCallbackAsync);
|
|
142
|
+
|
|
143
|
+
expect(result).toEqual(json);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should return fallback JSON if file not exists', async () => {
|
|
147
|
+
fileExists = false;
|
|
148
|
+
|
|
149
|
+
const result = await original.getJSONAsync(filename, createCallbackAsync);
|
|
150
|
+
|
|
151
|
+
expect(result).toEqual(fallbackJSON);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('checkJSON', () => {
|
|
156
|
+
it('should do nothing if json is truthy', () => {
|
|
157
|
+
original.checkJSON(filename, json);
|
|
158
|
+
|
|
159
|
+
expect(logger.error).not.toBeCalled();
|
|
160
|
+
});
|
|
161
|
+
it('should output error if json is falsy', () => {
|
|
162
|
+
expect(() => original.checkJSON(filename, '')).toThrowError(`File ${filename} doesn't exist and should be created with initial data, but function createCallback returned nothing`);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as colorette from 'colorette';
|
|
2
|
+
|
|
3
|
+
import logger from '../logger';
|
|
4
|
+
|
|
5
|
+
const text = 'text';
|
|
6
|
+
|
|
7
|
+
const originalConsole = global.console;
|
|
8
|
+
global.console.log = jest.fn();
|
|
9
|
+
global.console.info = jest.fn();
|
|
10
|
+
global.console.warn = jest.fn();
|
|
11
|
+
global.console.error = jest.fn();
|
|
12
|
+
|
|
13
|
+
const exit = jest.spyOn(process, 'exit').mockImplementation();
|
|
14
|
+
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
global.console = originalConsole;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('src/lib/logger', () => {
|
|
20
|
+
describe('log', () => {
|
|
21
|
+
it('should call console.log with original text', () => {
|
|
22
|
+
logger.log(text);
|
|
23
|
+
|
|
24
|
+
expect(global.console.log).toBeCalledWith(text);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('info', () => {
|
|
29
|
+
it('should call console.info with bright green text', () => {
|
|
30
|
+
logger.info(text);
|
|
31
|
+
|
|
32
|
+
expect(global.console.log).toBeCalledWith(colorette.greenBright(text));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('warn', () => {
|
|
37
|
+
it('should call console.warn with bright yellow text', () => {
|
|
38
|
+
logger.warn(text);
|
|
39
|
+
|
|
40
|
+
expect(global.console.warn).toBeCalledWith(colorette.yellowBright(text));
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('error', () => {
|
|
45
|
+
it('should call console.error with bright red text and newline', () => {
|
|
46
|
+
logger.error(text);
|
|
47
|
+
|
|
48
|
+
expect(global.console.error).toBeCalledWith(`${colorette.redBright(text)}\n`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should exit the process with code 1', () => {
|
|
52
|
+
logger.error(text);
|
|
53
|
+
|
|
54
|
+
expect(exit).toBeCalledWith(1);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import paths from '../paths';
|
|
5
|
+
const original = jest.requireActual('../paths').default as typeof paths;
|
|
6
|
+
jest.mock<typeof paths>('../paths', () => ({
|
|
7
|
+
ensureDir : jest.fn().mockImplementation((dirPath) => dirPath),
|
|
8
|
+
ensureFile : jest.fn().mockImplementation((filePath) => filePath),
|
|
9
|
+
getProfilesFile : jest.fn().mockImplementation(() => profilesFile),
|
|
10
|
+
getSecretsFile : jest.fn().mockImplementation(() => secretsFile),
|
|
11
|
+
getCredentialsFile : jest.fn().mockImplementation(() => credentialsFile),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
15
|
+
mkdirSync : jest.fn(),
|
|
16
|
+
writeFileSync : jest.fn(),
|
|
17
|
+
existsSync : jest.fn().mockImplementation(() => exists),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
jest.mock<Partial<typeof path>>('path', () => ({
|
|
21
|
+
join : jest.fn().mockImplementation((...args) => args.join('/')),
|
|
22
|
+
dirname : jest.fn().mockImplementation((arg) => arg.split('/').slice(0, -1).join('/')),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const profile = 'username';
|
|
26
|
+
const dirPath = 'dirPath';
|
|
27
|
+
const filePath = 'parentDir/filePath';
|
|
28
|
+
|
|
29
|
+
const profilesFile = 'input/profiles.json';
|
|
30
|
+
const secretsFile = 'secrets/username.json';
|
|
31
|
+
const credentialsFile = 'secrets/username.credentials.json';
|
|
32
|
+
|
|
33
|
+
let exists: boolean;
|
|
34
|
+
|
|
35
|
+
describe('src/lib/paths', () => {
|
|
36
|
+
|
|
37
|
+
describe('ensureDir', () => {
|
|
38
|
+
it('should create empty dir if not exists', () => {
|
|
39
|
+
exists = false;
|
|
40
|
+
|
|
41
|
+
original.ensureDir(dirPath);
|
|
42
|
+
|
|
43
|
+
expect(fs.mkdirSync).toBeCalledWith(dirPath, { recursive : true });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should not create empty dir if already exists', () => {
|
|
47
|
+
exists = true;
|
|
48
|
+
|
|
49
|
+
original.ensureDir(dirPath);
|
|
50
|
+
|
|
51
|
+
expect(fs.writeFileSync).not.toBeCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should return dirPath', () => {
|
|
55
|
+
const result = original.ensureDir(dirPath);
|
|
56
|
+
|
|
57
|
+
expect(result).toEqual(dirPath);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('ensureFile', () => {
|
|
62
|
+
it('should ensure parent dir', () => {
|
|
63
|
+
exists = false;
|
|
64
|
+
|
|
65
|
+
original.ensureFile(filePath);
|
|
66
|
+
|
|
67
|
+
expect(paths.ensureDir).toBeCalledWith('parentDir');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should create empty file if not exists', () => {
|
|
71
|
+
exists = false;
|
|
72
|
+
|
|
73
|
+
original.ensureFile(filePath);
|
|
74
|
+
|
|
75
|
+
expect(fs.writeFileSync).toBeCalledWith(filePath, '');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should not create empty file if already exists', () => {
|
|
79
|
+
exists = true;
|
|
80
|
+
|
|
81
|
+
original.ensureFile(filePath);
|
|
82
|
+
|
|
83
|
+
expect(fs.writeFileSync).not.toBeCalled();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should return filePath', () => {
|
|
87
|
+
const result = original.ensureFile(filePath);
|
|
88
|
+
|
|
89
|
+
expect(result).toEqual(filePath);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('getProfilesFile', () => {
|
|
94
|
+
it('should return profiles file', () => {
|
|
95
|
+
const result = original.getProfilesFile();
|
|
96
|
+
|
|
97
|
+
expect(result).toEqual(profilesFile);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('getSecretsFile', () => {
|
|
102
|
+
it('should return secrets file', () => {
|
|
103
|
+
const result = original.getSecretsFile(profile);
|
|
104
|
+
|
|
105
|
+
expect(result).toEqual(secretsFile);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('getCredentialsFile', () => {
|
|
110
|
+
it('should return credentials file', () => {
|
|
111
|
+
const result = original.getCredentialsFile(profile);
|
|
112
|
+
|
|
113
|
+
expect(result).toEqual(credentialsFile);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import jsonLib from '../jsonLib';
|
|
3
|
+
import logger from '../logger';
|
|
4
|
+
import paths from '../paths';
|
|
5
|
+
|
|
6
|
+
import profiles from '../profiles';
|
|
7
|
+
const original = jest.requireActual('../profiles').default as typeof profiles;
|
|
8
|
+
jest.mock<typeof profiles>('../profiles', () => ({
|
|
9
|
+
getProfiles : jest.fn().mockImplementation(() => existingProfiles),
|
|
10
|
+
setProfiles : jest.fn(),
|
|
11
|
+
createProfile : jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
15
|
+
mkdirSync : jest.fn(),
|
|
16
|
+
renameSync : jest.fn(),
|
|
17
|
+
writeFileSync : jest.fn(),
|
|
18
|
+
existsSync : jest.fn().mockImplementation((file) => existingFiles.includes(file)),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock<Partial<typeof jsonLib>>('../jsonLib', () => ({
|
|
22
|
+
getJSON : jest.fn().mockImplementation(() => json),
|
|
23
|
+
writeJSON : jest.fn(),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
jest.mock<Partial<typeof logger>>('../logger', () => ({
|
|
27
|
+
log : jest.fn(),
|
|
28
|
+
warn : jest.fn(),
|
|
29
|
+
error : jest.fn().mockImplementation((error) => {
|
|
30
|
+
throw error;
|
|
31
|
+
}) as jest.Mock<never, any>,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
jest.mock<Partial<typeof paths>>('../paths', () => ({
|
|
35
|
+
getProfilesFile : jest.fn().mockImplementation(() => profilesFile),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
const json = { key : 'value' };
|
|
39
|
+
const existingProfiles = [ 'username1', 'username2' ];
|
|
40
|
+
const profilesFile = 'profilesFile';
|
|
41
|
+
const profile1 = 'username1';
|
|
42
|
+
const profile2 = 'username2';
|
|
43
|
+
const allProfiles = [ profile1, profile2 ];
|
|
44
|
+
|
|
45
|
+
let existingFiles: string[] = [];
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
existingFiles = [];
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('src/lib/profiles', () => {
|
|
52
|
+
|
|
53
|
+
describe('getProfiles', () => {
|
|
54
|
+
const getJSONSpy = jest.spyOn(jsonLib, 'getJSON');
|
|
55
|
+
|
|
56
|
+
it('should get json from profiles file', () => {
|
|
57
|
+
original.getProfiles();
|
|
58
|
+
|
|
59
|
+
expect(getJSONSpy).toBeCalled();
|
|
60
|
+
expect(getJSONSpy.mock.calls[0][0]).toEqual(profilesFile);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should fallback to empty profiles array', () => {
|
|
64
|
+
original.getProfiles();
|
|
65
|
+
|
|
66
|
+
const fallback = getJSONSpy.mock.calls[0][1];
|
|
67
|
+
|
|
68
|
+
expect(fallback()).toEqual([]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should return JSON', () => {
|
|
72
|
+
const result = original.getProfiles();
|
|
73
|
+
|
|
74
|
+
expect(result).toEqual(json);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('setProfiles', () => {
|
|
79
|
+
it('should write json to profiles file', () => {
|
|
80
|
+
original.setProfiles(allProfiles);
|
|
81
|
+
|
|
82
|
+
expect(jsonLib.writeJSON).toBeCalledWith(profilesFile, allProfiles);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('createProfile', () => {
|
|
87
|
+
it('should output error and do nothing if profile is falsy', () => {
|
|
88
|
+
const func = () => original.createProfile('');
|
|
89
|
+
|
|
90
|
+
expect(func).toThrowError('Usage: `npm run create <profile>` where `profile` - is any profile name you want');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should get profiles', () => {
|
|
94
|
+
const newProfile = 'username1';
|
|
95
|
+
|
|
96
|
+
original.createProfile(newProfile);
|
|
97
|
+
|
|
98
|
+
expect(profiles.getProfiles).toBeCalledWith();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should not save profiles if profile already exists', () => {
|
|
102
|
+
const newProfile = 'username1';
|
|
103
|
+
|
|
104
|
+
original.createProfile(newProfile);
|
|
105
|
+
|
|
106
|
+
expect(profiles.setProfiles).not.toBeCalled();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should add new profile if not exists', () => {
|
|
110
|
+
const newProfile = 'newProfile';
|
|
111
|
+
|
|
112
|
+
original.createProfile(newProfile);
|
|
113
|
+
|
|
114
|
+
expect(profiles.setProfiles).toBeCalledWith([ 'username1', 'username2', 'newProfile' ]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|