@anmiles/google-api-wrapper 2.0.1 → 2.1.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/.vscode/settings.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,11 @@ 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
|
+
## [2.0.2](../../tags/v2.0.2) - 2023-03-13
|
|
9
|
+
### Added
|
|
10
|
+
- Calendars list API
|
|
11
|
+
- Export shared `getItems` to use for any other APIs
|
|
12
|
+
|
|
8
13
|
## [2.0.1](../../tags/v2.0.1) - 2023-03-12
|
|
9
14
|
### Changed
|
|
10
15
|
- Fixed exported types
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,11 +7,11 @@ import apiHelpers from './apiHelpers';
|
|
|
7
7
|
|
|
8
8
|
const original = jest.requireActual('../calendar').default as typeof calendar;
|
|
9
9
|
jest.mock<Partial<typeof calendar>>('../calendar', () => ({
|
|
10
|
-
getAPI : jest.fn().mockImplementation(async () => ({ events :
|
|
10
|
+
getAPI : jest.fn().mockImplementation(async () => ({ calendarList : calendarsAPI, events : eventsAPI })),
|
|
11
11
|
}));
|
|
12
12
|
|
|
13
13
|
jest.mock<Partial<typeof shared>>('../shared', () => ({
|
|
14
|
-
getItems : jest.fn()
|
|
14
|
+
getItems : jest.fn(),
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
17
|
jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
@@ -20,7 +20,7 @@ jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
|
20
20
|
|
|
21
21
|
jest.mock('googleapis', () => ({
|
|
22
22
|
google : {
|
|
23
|
-
calendar : jest.fn().mockImplementation(() => ({ events :
|
|
23
|
+
calendar : jest.fn().mockImplementation(() => ({ calendarList : calendarsAPI, events : eventsAPI })),
|
|
24
24
|
},
|
|
25
25
|
}));
|
|
26
26
|
|
|
@@ -28,12 +28,27 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
|
|
|
28
28
|
getAuth : jest.fn().mockImplementation(() => googleAuth),
|
|
29
29
|
}));
|
|
30
30
|
|
|
31
|
+
const getItemsSpy = jest.spyOn(shared, 'getItems');
|
|
32
|
+
|
|
31
33
|
const profile = 'username';
|
|
32
34
|
|
|
33
35
|
const googleAuth = {
|
|
34
36
|
setCredentials : jest.fn(),
|
|
35
37
|
};
|
|
36
38
|
|
|
39
|
+
const calendars: Array<{ summary?: string, description?: string, hidden?: boolean }> = [
|
|
40
|
+
{ summary : 'calendar 1', description : 'calendar 1 description', hidden : false },
|
|
41
|
+
{ summary : 'calendar 2', description : 'calendar 2 description', hidden : undefined },
|
|
42
|
+
{ summary : 'calendar 3', description : undefined, hidden : true },
|
|
43
|
+
{ summary : 'calendar 4', description : undefined, hidden : undefined },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const calendarsResponse = [
|
|
47
|
+
[ calendars[0], calendars[1] ],
|
|
48
|
+
null,
|
|
49
|
+
[ calendars[2], calendars[3] ],
|
|
50
|
+
];
|
|
51
|
+
|
|
37
52
|
const events: Array<{ summary?: string, source?: { url?: string, title?: string} }> = [
|
|
38
53
|
{ summary : 'event 1', source : { title : 'source 1', url : 'https://example.com' } },
|
|
39
54
|
{ summary : 'event 2', source : { title : 'source 2', url : undefined } },
|
|
@@ -53,8 +68,8 @@ const pageTokens = [
|
|
|
53
68
|
'token2',
|
|
54
69
|
];
|
|
55
70
|
|
|
56
|
-
const
|
|
57
|
-
const
|
|
71
|
+
const calendarsAPI = apiHelpers.getAPI(calendarsResponse, pageTokens);
|
|
72
|
+
const eventsAPI = apiHelpers.getAPI(eventsResponse, pageTokens);
|
|
58
73
|
|
|
59
74
|
describe('src/lib/api/calendar', () => {
|
|
60
75
|
describe('getAPI', () => {
|
|
@@ -73,11 +88,43 @@ describe('src/lib/api/calendar', () => {
|
|
|
73
88
|
it('should return calendar api', async () => {
|
|
74
89
|
const result = await original.getAPI(profile);
|
|
75
90
|
|
|
76
|
-
expect(result).toEqual({ events :
|
|
91
|
+
expect(result).toEqual({ calendarList : calendarsAPI, events : eventsAPI });
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('getCalendars', () => {
|
|
96
|
+
const args = { showHidden : true };
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
getItemsSpy.mockResolvedValue(calendars);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should get api', async () => {
|
|
103
|
+
await original.getCalendars(profile, args);
|
|
104
|
+
|
|
105
|
+
expect(calendar.getAPI).toBeCalledWith(profile);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should get items', async () => {
|
|
109
|
+
await original.getCalendars(profile, args);
|
|
110
|
+
|
|
111
|
+
expect(getItemsSpy).toBeCalledWith(calendarsAPI, args);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should return calendars', async () => {
|
|
115
|
+
const result = await original.getCalendars(profile, args);
|
|
116
|
+
|
|
117
|
+
expect(result).toEqual(calendars);
|
|
77
118
|
});
|
|
78
119
|
});
|
|
79
120
|
|
|
80
121
|
describe('getEvents', () => {
|
|
122
|
+
const args = { timeMin : '2010-01-01T00:00:00', timeMax : '2019-12-31T23:59:59' };
|
|
123
|
+
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
getItemsSpy.mockResolvedValue(events);
|
|
126
|
+
});
|
|
127
|
+
|
|
81
128
|
it('should get api', async () => {
|
|
82
129
|
await original.getEvents(profile, args);
|
|
83
130
|
|
|
@@ -87,7 +134,7 @@ describe('src/lib/api/calendar', () => {
|
|
|
87
134
|
it('should get items', async () => {
|
|
88
135
|
await original.getEvents(profile, args);
|
|
89
136
|
|
|
90
|
-
expect(
|
|
137
|
+
expect(getItemsSpy).toBeCalledWith(eventsAPI, args);
|
|
91
138
|
});
|
|
92
139
|
|
|
93
140
|
it('should return events', async () => {
|
|
@@ -98,19 +145,19 @@ describe('src/lib/api/calendar', () => {
|
|
|
98
145
|
});
|
|
99
146
|
|
|
100
147
|
describe('setEvent', () => {
|
|
101
|
-
const eventId
|
|
102
|
-
const
|
|
148
|
+
const eventId = 'eventId';
|
|
149
|
+
const args = { requestBody : { summary : 'summary' } };
|
|
103
150
|
|
|
104
151
|
it('should get api', async () => {
|
|
105
|
-
await original.setEvent(profile, eventId,
|
|
152
|
+
await original.setEvent(profile, eventId, args);
|
|
106
153
|
|
|
107
154
|
expect(calendar.getAPI).toBeCalledWith(profile);
|
|
108
155
|
});
|
|
109
156
|
|
|
110
157
|
it('should set items', async () => {
|
|
111
|
-
await original.setEvent(profile, eventId,
|
|
158
|
+
await original.setEvent(profile, eventId, args);
|
|
112
159
|
|
|
113
|
-
expect(
|
|
160
|
+
expect(eventsAPI.update).toBeCalledWith({ eventId, ...args });
|
|
114
161
|
});
|
|
115
162
|
});
|
|
116
163
|
});
|
|
@@ -7,11 +7,11 @@ import apiHelpers from './apiHelpers';
|
|
|
7
7
|
|
|
8
8
|
const original = jest.requireActual('../youtube').default as typeof youtube;
|
|
9
9
|
jest.mock<Partial<typeof youtube>>('../youtube', () => ({
|
|
10
|
-
getAPI : jest.fn().mockImplementation(async () => ({ playlistItems :
|
|
10
|
+
getAPI : jest.fn().mockImplementation(async () => ({ playlistItems : playlistItemsAPI })),
|
|
11
11
|
}));
|
|
12
12
|
|
|
13
13
|
jest.mock<Partial<typeof shared>>('../shared', () => ({
|
|
14
|
-
getItems : jest.fn()
|
|
14
|
+
getItems : jest.fn(),
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
17
|
jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
@@ -20,7 +20,7 @@ jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
|
20
20
|
|
|
21
21
|
jest.mock('googleapis', () => ({
|
|
22
22
|
google : {
|
|
23
|
-
youtube : jest.fn().mockImplementation(() => ({ playlistItems :
|
|
23
|
+
youtube : jest.fn().mockImplementation(() => ({ playlistItems : playlistItemsAPI })),
|
|
24
24
|
},
|
|
25
25
|
}));
|
|
26
26
|
|
|
@@ -28,6 +28,8 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
|
|
|
28
28
|
getAuth : jest.fn().mockImplementation(() => googleAuth),
|
|
29
29
|
}));
|
|
30
30
|
|
|
31
|
+
const getItemsSpy = jest.spyOn(shared, 'getItems');
|
|
32
|
+
|
|
31
33
|
const profile = 'username';
|
|
32
34
|
|
|
33
35
|
const googleAuth = {
|
|
@@ -53,8 +55,7 @@ const pageTokens = [
|
|
|
53
55
|
'token2',
|
|
54
56
|
];
|
|
55
57
|
|
|
56
|
-
const
|
|
57
|
-
const args = { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 };
|
|
58
|
+
const playlistItemsAPI = apiHelpers.getAPI(playlistItemsResponse, pageTokens);
|
|
58
59
|
|
|
59
60
|
describe('src/lib/api/youtube', () => {
|
|
60
61
|
describe('getAPI', () => {
|
|
@@ -73,11 +74,17 @@ describe('src/lib/api/youtube', () => {
|
|
|
73
74
|
it('should return youtube api', async () => {
|
|
74
75
|
const result = await original.getAPI(profile);
|
|
75
76
|
|
|
76
|
-
expect(result).toEqual({ playlistItems :
|
|
77
|
+
expect(result).toEqual({ playlistItems : playlistItemsAPI });
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
80
|
|
|
80
81
|
describe('getPlaylistItems', () => {
|
|
82
|
+
const args = { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 };
|
|
83
|
+
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
getItemsSpy.mockResolvedValue(playlistItems);
|
|
86
|
+
});
|
|
87
|
+
|
|
81
88
|
it('should get api', async () => {
|
|
82
89
|
await original.getPlaylistItems(profile, args);
|
|
83
90
|
|
|
@@ -87,7 +94,7 @@ describe('src/lib/api/youtube', () => {
|
|
|
87
94
|
it('should call getItems', async () => {
|
|
88
95
|
await original.getPlaylistItems(profile, args);
|
|
89
96
|
|
|
90
|
-
expect(
|
|
97
|
+
expect(getItemsSpy).toBeCalledWith(playlistItemsAPI, args);
|
|
91
98
|
});
|
|
92
99
|
|
|
93
100
|
it('should return videos', async () => {
|
package/src/lib/api/calendar.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { getAuth } from '../auth';
|
|
|
4
4
|
import { getItems } from './shared';
|
|
5
5
|
import calendar from './calendar';
|
|
6
6
|
|
|
7
|
-
export { getAPI, getEvents, setEvent };
|
|
8
|
-
export default { getAPI, getEvents, setEvent };
|
|
7
|
+
export { getAPI, getEvents, getCalendars, setEvent };
|
|
8
|
+
export default { getAPI, getEvents, getCalendars, setEvent };
|
|
9
9
|
|
|
10
10
|
async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar> {
|
|
11
11
|
const googleAuth = await getAuth(profile);
|
|
@@ -15,6 +15,12 @@ async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>
|
|
|
15
15
|
auth : googleAuth,
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
async function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List) {
|
|
20
|
+
const api = await calendar.getAPI(profile);
|
|
21
|
+
return getItems(api.calendarList, args);
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
async function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List) {
|
|
19
25
|
const api = await calendar.getAPI(profile);
|
|
20
26
|
return getItems(api.events, args);
|