@anmiles/google-api-wrapper 7.0.7 → 8.0.0
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/CHANGELOG.md +4 -0
- package/dist/lib/api/shared.js +5 -2
- package/dist/lib/api/shared.js.map +1 -1
- package/dist/lib/paths.d.ts +1 -5
- package/dist/lib/paths.js +2 -19
- package/dist/lib/paths.js.map +1 -1
- package/dist/lib/profiles.d.ts +1 -0
- package/dist/lib/profiles.js +4 -3
- package/dist/lib/profiles.js.map +1 -1
- package/dist/lib/secrets.d.ts +5 -1
- package/dist/lib/secrets.js +15 -13
- package/dist/lib/secrets.js.map +1 -1
- package/package.json +3 -1
- package/src/lib/__tests__/paths.test.ts +1 -63
- package/src/lib/__tests__/profiles.test.ts +16 -9
- package/src/lib/__tests__/secrets.test.ts +65 -51
- package/src/lib/api/__tests__/shared.test.ts +4 -6
- package/src/lib/api/shared.ts +1 -1
- package/src/lib/paths.ts +2 -20
- package/src/lib/profiles.ts +4 -3
- package/src/lib/secrets.ts +18 -15
- package/dist/lib/jsonLib.d.ts +0 -14
- package/dist/lib/jsonLib.js +0 -55
- package/dist/lib/jsonLib.js.map +0 -1
- package/dist/lib/sleep.d.ts +0 -6
- package/dist/lib/sleep.js +0 -11
- package/dist/lib/sleep.js.map +0 -1
- package/src/lib/__tests__/jsonLib.test.ts +0 -245
- package/src/lib/__tests__/sleep.test.ts +0 -17
- package/src/lib/jsonLib.ts +0 -57
- package/src/lib/sleep.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [8.0.0](../../tags/v8.0.0) - 2023-05-08
|
|
9
|
+
### Changed
|
|
10
|
+
- Use `@anmiles/prototypes` instead of old built-in fs functions
|
|
11
|
+
|
|
8
12
|
## [7.0.7](../../tags/v7.0.7) - 2023-05-07
|
|
9
13
|
### Changed
|
|
10
14
|
- Move repository
|
package/dist/lib/api/shared.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getItems = void 0;
|
|
4
7
|
const logger_1 = require("@anmiles/logger");
|
|
5
|
-
const sleep_1 = require("
|
|
8
|
+
const sleep_1 = __importDefault(require("@anmiles/sleep"));
|
|
6
9
|
exports.default = { getItems };
|
|
7
10
|
const requestInterval = 300;
|
|
8
11
|
async function getItems(api, params, options) {
|
|
@@ -15,7 +18,7 @@ async function getItems(api, params, options) {
|
|
|
15
18
|
if (!(options === null || options === void 0 ? void 0 : options.hideProgress)) {
|
|
16
19
|
(0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
|
|
17
20
|
}
|
|
18
|
-
await (0, sleep_1.
|
|
21
|
+
await (0, sleep_1.default)(requestInterval);
|
|
19
22
|
pageToken = response.data.nextPageToken;
|
|
20
23
|
} while (pageToken);
|
|
21
24
|
return items;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;;;;AACA,4CAAsC;AACtC,2DAAmC;AAInC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAE5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAiB5B,KAAK,UAAU,QAAQ,CAAQ,GAAqB,EAAE,MAAW,EAAE,OAAuB;;IACzF,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAA4D,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QACnH,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAA,EAAE;YAC3B,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;SAC/F;QAED,MAAM,IAAA,eAAK,EAAC,eAAe,CAAC,CAAC;QAC7B,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;KACxC,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AAtCQ,4BAAQ"}
|
package/dist/lib/paths.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getProfilesFile, getScopesFile, getSecretsFile, getCredentialsFile };
|
|
2
2
|
declare const _default: {
|
|
3
|
-
ensureDir: typeof ensureDir;
|
|
4
|
-
ensureFile: typeof ensureFile;
|
|
5
3
|
getProfilesFile: typeof getProfilesFile;
|
|
6
4
|
getScopesFile: typeof getScopesFile;
|
|
7
5
|
getSecretsFile: typeof getSecretsFile;
|
|
8
6
|
getCredentialsFile: typeof getCredentialsFile;
|
|
9
7
|
};
|
|
10
8
|
export default _default;
|
|
11
|
-
declare function ensureDir(dirPath: string): string;
|
|
12
|
-
declare function ensureFile(filePath: string): string;
|
|
13
9
|
declare function getProfilesFile(): string;
|
|
14
10
|
declare function getScopesFile(): string;
|
|
15
11
|
declare function getSecretsFile(profile: string): string;
|
package/dist/lib/paths.js
CHANGED
|
@@ -3,30 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCredentialsFile = exports.getSecretsFile = exports.getScopesFile = exports.getProfilesFile =
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
6
|
+
exports.getCredentialsFile = exports.getSecretsFile = exports.getScopesFile = exports.getProfilesFile = void 0;
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
exports.default = { ensureDir, ensureFile, getProfilesFile, getScopesFile, getSecretsFile, getCredentialsFile };
|
|
8
|
+
exports.default = { getProfilesFile, getScopesFile, getSecretsFile, getCredentialsFile };
|
|
11
9
|
const dirPaths = {
|
|
12
10
|
input: 'input',
|
|
13
11
|
secrets: 'secrets',
|
|
14
12
|
};
|
|
15
|
-
function ensureDir(dirPath) {
|
|
16
|
-
if (!fs_1.default.existsSync(dirPath)) {
|
|
17
|
-
fs_1.default.mkdirSync(dirPath, { recursive: true });
|
|
18
|
-
}
|
|
19
|
-
return dirPath;
|
|
20
|
-
}
|
|
21
|
-
exports.ensureDir = ensureDir;
|
|
22
|
-
function ensureFile(filePath) {
|
|
23
|
-
paths_1.default.ensureDir(path_1.default.dirname(filePath));
|
|
24
|
-
if (!fs_1.default.existsSync(filePath)) {
|
|
25
|
-
fs_1.default.writeFileSync(filePath, '');
|
|
26
|
-
}
|
|
27
|
-
return filePath;
|
|
28
|
-
}
|
|
29
|
-
exports.ensureFile = ensureFile;
|
|
30
13
|
function getProfilesFile() {
|
|
31
14
|
return path_1.default.join(dirPaths.input, 'profiles.json');
|
|
32
15
|
}
|
package/dist/lib/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAGxB,kBAAe,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;AAEtF,MAAM,QAAQ,GAAG;IAChB,KAAK,EAAK,OAAO;IACjB,OAAO,EAAG,SAAS;CACnB,CAAC;AAEF,SAAS,eAAe;IACvB,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AACnD,CAAC;AAVQ,0CAAe;AAYxB,SAAS,aAAa;IACrB,OAAO,aAAa,CAAC;AACtB,CAAC;AAdyB,sCAAa;AAgBvC,SAAS,cAAc,CAAC,OAAe;IACtC,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,OAAO,CAAC,CAAC;AACvD,CAAC;AAlBwC,wCAAc;AAoBvD,SAAS,kBAAkB,CAAC,OAAe;IAC1C,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,mBAAmB,CAAC,CAAC;AACnE,CAAC;AAtBwD,gDAAkB"}
|
package/dist/lib/profiles.d.ts
CHANGED
package/dist/lib/profiles.js
CHANGED
|
@@ -4,18 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createProfile = exports.setProfiles = exports.getProfiles = void 0;
|
|
7
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
require("@anmiles/prototypes");
|
|
8
9
|
const paths_1 = require("./paths");
|
|
9
10
|
const profiles_1 = __importDefault(require("./profiles"));
|
|
10
11
|
exports.default = { getProfiles, setProfiles, createProfile };
|
|
11
12
|
function getProfiles() {
|
|
12
13
|
const profilesFile = (0, paths_1.getProfilesFile)();
|
|
13
|
-
return
|
|
14
|
+
return fs_1.default.getJSON(profilesFile, () => []);
|
|
14
15
|
}
|
|
15
16
|
exports.getProfiles = getProfiles;
|
|
16
17
|
function setProfiles(profiles) {
|
|
17
18
|
const profilesFile = (0, paths_1.getProfilesFile)();
|
|
18
|
-
|
|
19
|
+
fs_1.default.writeJSON(profilesFile, profiles);
|
|
19
20
|
}
|
|
20
21
|
exports.setProfiles = setProfiles;
|
|
21
22
|
function createProfile(profile) {
|
package/dist/lib/profiles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAA6B;AAC7B,mCAA0C;AAE1C,0DAAkC;AAGlC,kBAAe,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC;AAE3D,SAAS,WAAW;IACnB,MAAM,YAAY,GAAG,IAAA,uBAAe,GAAE,CAAC;IACvC,OAAO,YAAE,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AAC3C,CAAC;AANQ,kCAAW;AAQpB,SAAS,WAAW,CAAC,QAAkB;IACtC,MAAM,YAAY,GAAG,IAAA,uBAAe,GAAE,CAAC;IACvC,YAAE,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAXqB,kCAAW;AAajC,SAAS,aAAa,CAAC,OAAe;IACrC,IAAI,CAAC,OAAO,EAAE;QACb,MAAM,kFAAkF,CAAC;KACzF;IAED,MAAM,gBAAgB,GAAG,kBAAQ,CAAC,WAAW,EAAE,CAAC;IAEhD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACvC,OAAO;KACP;IAED,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,kBAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AACxC,CAAC;AA1BkC,sCAAa"}
|
package/dist/lib/secrets.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
2
|
import type { Secrets, AuthOptions } from '../types';
|
|
3
|
+
import '@anmiles/prototypes';
|
|
3
4
|
export { getSecrets, getCredentials };
|
|
4
5
|
declare const _default: {
|
|
5
6
|
getScopes: typeof getScopes;
|
|
@@ -15,7 +16,10 @@ export default _default;
|
|
|
15
16
|
declare function getScopes(): string[];
|
|
16
17
|
declare function getSecrets(profile: string): Secrets;
|
|
17
18
|
declare function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials>;
|
|
18
|
-
declare function validateCredentials(credentials: GoogleApis.Auth.Credentials): Promise<
|
|
19
|
+
declare function validateCredentials(credentials: GoogleApis.Auth.Credentials): Promise<{
|
|
20
|
+
isValid: boolean;
|
|
21
|
+
validationError?: string;
|
|
22
|
+
}>;
|
|
19
23
|
declare function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client, options?: AuthOptions, prompt?: GoogleApis.Auth.GenerateAuthUrlOpts['prompt']): Promise<GoogleApis.Auth.Credentials>;
|
|
20
24
|
declare function checkSecrets(profile: string, secretsObject: Secrets, secretsFile: string): true | void;
|
|
21
25
|
declare function getScopesError(scopesFile: string): string;
|
package/dist/lib/secrets.js
CHANGED
|
@@ -4,11 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getCredentials = exports.getSecrets = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const http_1 = __importDefault(require("http"));
|
|
8
9
|
const server_destroy_1 = __importDefault(require("server-destroy"));
|
|
9
10
|
const open_1 = __importDefault(require("open"));
|
|
10
11
|
const logger_1 = require("@anmiles/logger");
|
|
11
|
-
|
|
12
|
+
require("@anmiles/prototypes");
|
|
12
13
|
const paths_1 = require("./paths");
|
|
13
14
|
const secrets_1 = __importDefault(require("./secrets"));
|
|
14
15
|
exports.default = { getScopes, getSecrets, getCredentials, validateCredentials, createCredentials, checkSecrets, getSecretsError, getScopesError };
|
|
@@ -18,14 +19,14 @@ const callbackURI = `http://localhost:${callbackPort}/oauthcallback`;
|
|
|
18
19
|
const tokenExpiration = 7 * 24 * 60 * 60 * 1000;
|
|
19
20
|
function getScopes() {
|
|
20
21
|
const scopesFile = (0, paths_1.getScopesFile)();
|
|
21
|
-
const scopes =
|
|
22
|
+
const scopes = fs_1.default.getJSON(scopesFile, () => {
|
|
22
23
|
throw secrets_1.default.getScopesError(scopesFile);
|
|
23
24
|
});
|
|
24
25
|
return scopes;
|
|
25
26
|
}
|
|
26
27
|
function getSecrets(profile) {
|
|
27
28
|
const secretsFile = (0, paths_1.getSecretsFile)(profile);
|
|
28
|
-
const secretsObject =
|
|
29
|
+
const secretsObject = fs_1.default.getJSON(secretsFile, () => {
|
|
29
30
|
throw secrets_1.default.getSecretsError(profile, secretsFile);
|
|
30
31
|
});
|
|
31
32
|
secrets_1.default.checkSecrets(profile, secretsObject, secretsFile);
|
|
@@ -37,27 +38,28 @@ async function getCredentials(profile, auth, options) {
|
|
|
37
38
|
if (options === null || options === void 0 ? void 0 : options.temporary) {
|
|
38
39
|
return secrets_1.default.createCredentials(profile, auth, options);
|
|
39
40
|
}
|
|
40
|
-
return
|
|
41
|
+
return fs_1.default.getJSONAsync(credentialsFile, async () => {
|
|
42
|
+
const refreshToken = fs_1.default.existsSync(credentialsFile) ? fs_1.default.readJSON(credentialsFile).refresh_token : undefined;
|
|
43
|
+
const credentials = await secrets_1.default.createCredentials(profile, auth, options, refreshToken ? undefined : 'consent');
|
|
41
44
|
// eslint-disable-next-line camelcase
|
|
42
|
-
|
|
43
|
-
// eslint-disable-next-line camelcase
|
|
44
|
-
const credentials = await secrets_1.default.createCredentials(profile, auth, options, refresh_token ? undefined : 'consent');
|
|
45
|
-
// eslint-disable-next-line camelcase
|
|
46
|
-
return { refresh_token, ...credentials };
|
|
45
|
+
return { refresh_token: refreshToken, ...credentials };
|
|
47
46
|
}, secrets_1.default.validateCredentials);
|
|
48
47
|
}
|
|
49
48
|
exports.getCredentials = getCredentials;
|
|
50
49
|
async function validateCredentials(credentials) {
|
|
51
50
|
if (!credentials.access_token) {
|
|
52
|
-
return false;
|
|
51
|
+
return { isValid: false, validationError: 'Credentials does not have access_token' };
|
|
53
52
|
}
|
|
54
53
|
if (!credentials.refresh_token) {
|
|
55
|
-
return false;
|
|
54
|
+
return { isValid: false, validationError: 'Credentials does not have refresh_token' };
|
|
56
55
|
}
|
|
57
56
|
if (!credentials.expiry_date) {
|
|
58
|
-
return
|
|
57
|
+
return { isValid: false, validationError: 'Credentials does not have expiry_date' };
|
|
58
|
+
}
|
|
59
|
+
if (new Date().getTime() - credentials.expiry_date >= tokenExpiration) {
|
|
60
|
+
return { isValid: false, validationError: 'Credentials expired' };
|
|
59
61
|
}
|
|
60
|
-
return
|
|
62
|
+
return { isValid: true };
|
|
61
63
|
}
|
|
62
64
|
async function createCredentials(profile, auth, options, prompt) {
|
|
63
65
|
const scope = (options === null || options === void 0 ? void 0 : options.scopes) || secrets_1.default.getScopes();
|
package/dist/lib/secrets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/lib/secrets.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oEAA2C;AAC3C,gDAAwB;AAExB,4CAAuC;AAEvC
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/lib/sec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yDAAyD;QACzD,iDAAiD;QACjD,qDAAqD;QACrD,2BAA2B;QAC3B,wBAAwB;QACxB,wCAAwC;QACxC,0GAA0G;QAC1G,mCAAmC;QACnC,oCAAoC;QACpC,uBAAuB,iBAAO,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACtD,mCAAmC;QACnC,yBAAyB;QACzB,wBAAwB;QACxB,mCAAmC;QACnC,oDAAoD;QACpD,6CAA6C;QAC7C,+DAA+D;QAC/D,mDAAmD;QACnD,yCAAyC;QACzC,wCAAwC,WAAW,EAAE;QACrD,wBAAwB;QACxB,uEAAuE,OAAO,OAAO;QACrF,8BAA8B;KAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anmiles/google-api-wrapper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Provides quick interface for getting google API data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"google",
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@anmiles/logger": "^2.1.2",
|
|
33
|
+
"@anmiles/prototypes": "^2.0.0",
|
|
34
|
+
"@anmiles/sleep": "^1.0.2",
|
|
33
35
|
"execa": "^5.1.1",
|
|
34
36
|
"googleapis": "^118.0.0",
|
|
35
37
|
"open": "^8.4.2",
|
|
@@ -4,8 +4,6 @@ import path from 'path';
|
|
|
4
4
|
import paths from '../paths';
|
|
5
5
|
const original = jest.requireActual('../paths').default as typeof paths;
|
|
6
6
|
jest.mock<typeof paths>('../paths', () => ({
|
|
7
|
-
ensureDir : jest.fn().mockImplementation((dirPath) => dirPath),
|
|
8
|
-
ensureFile : jest.fn().mockImplementation((filePath) => filePath),
|
|
9
7
|
getProfilesFile : jest.fn().mockImplementation(() => profilesFile),
|
|
10
8
|
getScopesFile : jest.fn().mockImplementation(() => scopesFile),
|
|
11
9
|
getSecretsFile : jest.fn().mockImplementation(() => secretsFile),
|
|
@@ -23,10 +21,7 @@ jest.mock<Partial<typeof path>>('path', () => ({
|
|
|
23
21
|
dirname : jest.fn().mockImplementation((arg) => arg.split('/').slice(0, -1).join('/')),
|
|
24
22
|
}));
|
|
25
23
|
|
|
26
|
-
const profile
|
|
27
|
-
const dirPath = 'dirPath';
|
|
28
|
-
const filePath = 'parentDir/filePath';
|
|
29
|
-
|
|
24
|
+
const profile = 'username';
|
|
30
25
|
const profilesFile = 'input/profiles.json';
|
|
31
26
|
const scopesFile = 'scopes.json';
|
|
32
27
|
const secretsFile = 'secrets/username.json';
|
|
@@ -35,63 +30,6 @@ const credentialsFile = 'secrets/username.credentials.json';
|
|
|
35
30
|
let exists: boolean;
|
|
36
31
|
|
|
37
32
|
describe('src/lib/paths', () => {
|
|
38
|
-
|
|
39
|
-
describe('ensureDir', () => {
|
|
40
|
-
it('should create empty dir if not exists', () => {
|
|
41
|
-
exists = false;
|
|
42
|
-
|
|
43
|
-
original.ensureDir(dirPath);
|
|
44
|
-
|
|
45
|
-
expect(fs.mkdirSync).toHaveBeenCalledWith(dirPath, { recursive : true });
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should not create empty dir if already exists', () => {
|
|
49
|
-
exists = true;
|
|
50
|
-
|
|
51
|
-
original.ensureDir(dirPath);
|
|
52
|
-
|
|
53
|
-
expect(fs.writeFileSync).not.toHaveBeenCalled();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should return dirPath', () => {
|
|
57
|
-
const result = original.ensureDir(dirPath);
|
|
58
|
-
|
|
59
|
-
expect(result).toEqual(dirPath);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('ensureFile', () => {
|
|
64
|
-
it('should ensure parent dir', () => {
|
|
65
|
-
exists = false;
|
|
66
|
-
|
|
67
|
-
original.ensureFile(filePath);
|
|
68
|
-
|
|
69
|
-
expect(paths.ensureDir).toHaveBeenCalledWith('parentDir');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should create empty file if not exists', () => {
|
|
73
|
-
exists = false;
|
|
74
|
-
|
|
75
|
-
original.ensureFile(filePath);
|
|
76
|
-
|
|
77
|
-
expect(fs.writeFileSync).toHaveBeenCalledWith(filePath, '');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should not create empty file if already exists', () => {
|
|
81
|
-
exists = true;
|
|
82
|
-
|
|
83
|
-
original.ensureFile(filePath);
|
|
84
|
-
|
|
85
|
-
expect(fs.writeFileSync).not.toHaveBeenCalled();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should return filePath', () => {
|
|
89
|
-
const result = original.ensureFile(filePath);
|
|
90
|
-
|
|
91
|
-
expect(result).toEqual(filePath);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
33
|
describe('getProfilesFile', () => {
|
|
96
34
|
it('should return profiles file', () => {
|
|
97
35
|
const result = original.getProfilesFile();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import logger from '@anmiles/logger';
|
|
3
|
-
import jsonLib from '../jsonLib';
|
|
4
3
|
import paths from '../paths';
|
|
5
4
|
|
|
6
5
|
import profiles from '../profiles';
|
|
@@ -18,11 +17,6 @@ jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
|
18
17
|
existsSync : jest.fn().mockImplementation((file) => existingFiles.includes(file)),
|
|
19
18
|
}));
|
|
20
19
|
|
|
21
|
-
jest.mock<Partial<typeof jsonLib>>('../jsonLib', () => ({
|
|
22
|
-
getJSON : jest.fn().mockImplementation(() => json),
|
|
23
|
-
writeJSON : jest.fn(),
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
20
|
jest.mock<Partial<typeof logger>>('@anmiles/logger', () => ({
|
|
27
21
|
log : jest.fn(),
|
|
28
22
|
warn : jest.fn(),
|
|
@@ -41,15 +35,28 @@ const allProfiles = [ profile1, profile2 ];
|
|
|
41
35
|
|
|
42
36
|
let existingFiles: string[] = [];
|
|
43
37
|
|
|
38
|
+
let getJSONSpy: jest.SpyInstance;
|
|
39
|
+
let writeJSONSpy: jest.SpyInstance;
|
|
40
|
+
|
|
41
|
+
beforeAll(() => {
|
|
42
|
+
getJSONSpy = jest.spyOn(fs, 'getJSON');
|
|
43
|
+
writeJSONSpy = jest.spyOn(fs, 'writeJSON');
|
|
44
|
+
});
|
|
45
|
+
|
|
44
46
|
beforeEach(() => {
|
|
47
|
+
getJSONSpy.mockImplementation(() => json);
|
|
48
|
+
writeJSONSpy.mockImplementation();
|
|
45
49
|
existingFiles = [];
|
|
46
50
|
});
|
|
47
51
|
|
|
52
|
+
afterAll(() => {
|
|
53
|
+
getJSONSpy.mockRestore();
|
|
54
|
+
writeJSONSpy.mockRestore();
|
|
55
|
+
});
|
|
56
|
+
|
|
48
57
|
describe('src/lib/profiles', () => {
|
|
49
58
|
|
|
50
59
|
describe('getProfiles', () => {
|
|
51
|
-
const getJSONSpy = jest.spyOn(jsonLib, 'getJSON');
|
|
52
|
-
|
|
53
60
|
it('should get json from profiles file', () => {
|
|
54
61
|
original.getProfiles();
|
|
55
62
|
|
|
@@ -76,7 +83,7 @@ describe('src/lib/profiles', () => {
|
|
|
76
83
|
it('should write json to profiles file', () => {
|
|
77
84
|
original.setProfiles(allProfiles);
|
|
78
85
|
|
|
79
|
-
expect(
|
|
86
|
+
expect(writeJSONSpy).toHaveBeenCalledWith(profilesFile, allProfiles);
|
|
80
87
|
});
|
|
81
88
|
});
|
|
82
89
|
|