@anmiles/google-api-wrapper 3.0.0 → 3.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/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
|
+
## [3.0.1](../../tags/v3.0.1) - 2023-03-12
|
|
9
|
+
### Changed
|
|
10
|
+
- Fixed path to scopes file
|
|
11
|
+
|
|
8
12
|
## [3.0.0](../../tags/v3.0.0) - 2023-03-13
|
|
9
13
|
### Changed
|
|
10
14
|
- Revised auth instructions
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@ const dirPath = 'dirPath';
|
|
|
28
28
|
const filePath = 'parentDir/filePath';
|
|
29
29
|
|
|
30
30
|
const profilesFile = 'input/profiles.json';
|
|
31
|
-
const scopesFile = '
|
|
31
|
+
const scopesFile = 'scopes.json';
|
|
32
32
|
const secretsFile = 'secrets/username.json';
|
|
33
33
|
const credentialsFile = 'secrets/username.credentials.json';
|
|
34
34
|
|
|
@@ -9,13 +9,13 @@ import type { Secrets } from '../../types';
|
|
|
9
9
|
import secrets from '../secrets';
|
|
10
10
|
const original = jest.requireActual('../secrets').default as typeof secrets;
|
|
11
11
|
jest.mock<typeof secrets>('../secrets', () => ({
|
|
12
|
-
getScopes
|
|
13
|
-
getSecrets
|
|
14
|
-
getCredentials
|
|
12
|
+
getScopes : jest.fn().mockImplementation(() => scopesJSON),
|
|
13
|
+
getSecrets : jest.fn().mockImplementation(() => secretsJSON),
|
|
14
|
+
getCredentials : jest.fn(),
|
|
15
15
|
createCredentials : jest.fn(),
|
|
16
|
-
checkSecrets
|
|
17
|
-
getScopesError
|
|
18
|
-
getSecretsError: jest.fn().mockImplementation(() => secretsError),
|
|
16
|
+
checkSecrets : jest.fn(),
|
|
17
|
+
getScopesError : jest.fn().mockImplementation(() => scopesError),
|
|
18
|
+
getSecretsError : jest.fn().mockImplementation(() => secretsError),
|
|
19
19
|
}));
|
|
20
20
|
|
|
21
21
|
jest.mock<Partial<typeof http>>('http', () => ({
|
|
@@ -38,7 +38,7 @@ jest.mock<Partial<typeof colorette>>('colorette', () => ({
|
|
|
38
38
|
}));
|
|
39
39
|
|
|
40
40
|
jest.mock<Partial<typeof jsonLib>>('../jsonLib', () => ({
|
|
41
|
-
getJSON
|
|
41
|
+
getJSON : jest.fn().mockImplementation(() => json),
|
|
42
42
|
getJSONAsync : jest.fn().mockImplementation(async () => json),
|
|
43
43
|
}));
|
|
44
44
|
|
|
@@ -49,9 +49,9 @@ jest.mock<Partial<typeof logger>>('../logger', () => ({
|
|
|
49
49
|
}) as jest.Mock<never, any>,
|
|
50
50
|
}));
|
|
51
51
|
|
|
52
|
-
const profile
|
|
53
|
-
const scopesFile
|
|
54
|
-
const secretsFile
|
|
52
|
+
const profile = 'username1';
|
|
53
|
+
const scopesFile = 'scopes.json';
|
|
54
|
+
const secretsFile = 'secrets/username1.json';
|
|
55
55
|
const credentialsFile = 'secrets/username1.credentials.json';
|
|
56
56
|
const wrongRedirectURI = 'wrong_redirect_uri';
|
|
57
57
|
|
|
@@ -66,13 +66,13 @@ const scopesJSON: string[] = [
|
|
|
66
66
|
const secretsJSON: Secrets = {
|
|
67
67
|
web : {
|
|
68
68
|
/* eslint-disable camelcase */
|
|
69
|
-
client_id
|
|
70
|
-
project_id
|
|
71
|
-
auth_uri
|
|
72
|
-
token_uri
|
|
69
|
+
client_id : 'client_id.apps.googleusercontent.com',
|
|
70
|
+
project_id : 'project_id',
|
|
71
|
+
auth_uri : 'https://accounts.google.com/o/oauth2/auth',
|
|
72
|
+
token_uri : 'https://oauth2.googleapis.com/token',
|
|
73
73
|
auth_provider_x509_cert_url : 'https://www.googleapis.com/oauth2/v1/certs',
|
|
74
|
-
client_secret
|
|
75
|
-
redirect_uris
|
|
74
|
+
client_secret : 'client_secret',
|
|
75
|
+
redirect_uris : [ 'http://localhost:6006/oauthcallback' ],
|
|
76
76
|
/* eslint-enable camelcase */
|
|
77
77
|
},
|
|
78
78
|
};
|
|
@@ -83,11 +83,11 @@ const credentialsJSON = {
|
|
|
83
83
|
|
|
84
84
|
let json: object;
|
|
85
85
|
|
|
86
|
-
const code
|
|
86
|
+
const code = 'code';
|
|
87
87
|
const authUrl = 'https://authUrl';
|
|
88
|
-
const auth
|
|
88
|
+
const auth = {
|
|
89
89
|
generateAuthUrl : jest.fn().mockReturnValue(authUrl),
|
|
90
|
-
getToken
|
|
90
|
+
getToken : jest.fn().mockReturnValue({ tokens : credentialsJSON }),
|
|
91
91
|
} as unknown as GoogleApis.Common.OAuth2Client;
|
|
92
92
|
|
|
93
93
|
let request: http.IncomingMessage;
|
|
@@ -208,7 +208,7 @@ describe('src/lib/secrets', () => {
|
|
|
208
208
|
|
|
209
209
|
beforeEach(() => {
|
|
210
210
|
request = {
|
|
211
|
-
url
|
|
211
|
+
url : `/request.url?code=${code}`,
|
|
212
212
|
headers : {
|
|
213
213
|
host : 'localhost:6006',
|
|
214
214
|
},
|
|
@@ -223,7 +223,7 @@ describe('src/lib/secrets', () => {
|
|
|
223
223
|
expect(auth.generateAuthUrl).toBeCalledWith({
|
|
224
224
|
// eslint-disable-next-line camelcase
|
|
225
225
|
access_type : 'offline',
|
|
226
|
-
scope
|
|
226
|
+
scope : [
|
|
227
227
|
'https://www.googleapis.com/auth/calendar.calendars.readonly',
|
|
228
228
|
'https://www.googleapis.com/auth/calendar.events.readonly',
|
|
229
229
|
],
|
|
@@ -265,9 +265,9 @@ describe('src/lib/secrets', () => {
|
|
|
265
265
|
|
|
266
266
|
it('should only resolve when request.url is truthy', async () => {
|
|
267
267
|
const emptyRequestTime = 100;
|
|
268
|
-
const requestTime
|
|
269
|
-
const emptyRequest
|
|
270
|
-
emptyRequest.url
|
|
268
|
+
const requestTime = 200;
|
|
269
|
+
const emptyRequest = { ...request } as http.IncomingMessage;
|
|
270
|
+
emptyRequest.url = undefined;
|
|
271
271
|
|
|
272
272
|
const before = new Date().getTime();
|
|
273
273
|
willOpen(emptyRequest, emptyRequestTime);
|
|
@@ -284,9 +284,9 @@ describe('src/lib/secrets', () => {
|
|
|
284
284
|
|
|
285
285
|
it('should only resolve when request.url contains no code', async () => {
|
|
286
286
|
const noCodeRequestTime = 100;
|
|
287
|
-
const requestTime
|
|
288
|
-
const noCodeRequest
|
|
289
|
-
noCodeRequest.url
|
|
287
|
+
const requestTime = 200;
|
|
288
|
+
const noCodeRequest = { ...request } as http.IncomingMessage;
|
|
289
|
+
noCodeRequest.url = '/request.url?param=value';
|
|
290
290
|
|
|
291
291
|
const before = new Date().getTime();
|
|
292
292
|
willOpen(noCodeRequest, noCodeRequestTime);
|
|
@@ -318,9 +318,9 @@ describe('src/lib/secrets', () => {
|
|
|
318
318
|
});
|
|
319
319
|
|
|
320
320
|
it('should output error if redirect_uri is incorrect', () => {
|
|
321
|
-
const wrongSecretsJSON
|
|
321
|
+
const wrongSecretsJSON = { ...secretsJSON };
|
|
322
322
|
wrongSecretsJSON.web.redirect_uris[0] = wrongRedirectURI;
|
|
323
|
-
const func
|
|
323
|
+
const func = () => original.checkSecrets(profile, wrongSecretsJSON, secretsFile);
|
|
324
324
|
|
|
325
325
|
expect(func).toThrowError('Error in credentials file: redirect URI should be http://localhost:6006/oauthcallback.\nsecretsError');
|
|
326
326
|
});
|