@insignia-education/api-sdk-js 0.9.12
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/.github/hooks/pre-commit +13 -0
- package/.github/workflows/npm-publish-github-packages.yml +30 -0
- package/Cart.js +40 -0
- package/LICENSE +21 -0
- package/README.md +444 -0
- package/babel.config.cjs +1 -0
- package/coverage/clover.xml +703 -0
- package/coverage/coverage-final.json +30 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/Client.js.html +202 -0
- package/coverage/lcov-report/src/api/v1/Accounts.js.html +151 -0
- package/coverage/lcov-report/src/api/v1/Auth.js.html +130 -0
- package/coverage/lcov-report/src/api/v1/Categories.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Changelogs.js.html +118 -0
- package/coverage/lcov-report/src/api/v1/Configs.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/ContactForms.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/ConversationalTopics.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Countries.js.html +112 -0
- package/coverage/lcov-report/src/api/v1/Coupons.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Courses.js.html +328 -0
- package/coverage/lcov-report/src/api/v1/Currencies.js.html +115 -0
- package/coverage/lcov-report/src/api/v1/Files.js.html +115 -0
- package/coverage/lcov-report/src/api/v1/Forums.js.html +157 -0
- package/coverage/lcov-report/src/api/v1/Hashes.js.html +118 -0
- package/coverage/lcov-report/src/api/v1/Insignias.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Languages.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/MailBlacklist.js.html +118 -0
- package/coverage/lcov-report/src/api/v1/Organizations.js.html +118 -0
- package/coverage/lcov-report/src/api/v1/Quizzes.js.html +181 -0
- package/coverage/lcov-report/src/api/v1/ShortLinks.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Surveys.js.html +181 -0
- package/coverage/lcov-report/src/api/v1/Tags.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Taxes.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Teacher.js.html +196 -0
- package/coverage/lcov-report/src/api/v1/Translations.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/UserTypes.js.html +121 -0
- package/coverage/lcov-report/src/api/v1/Users.js.html +331 -0
- package/coverage/lcov-report/src/api/v1/Zoom.js.html +154 -0
- package/coverage/lcov-report/src/api/v1/index.html +521 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov.info +1822 -0
- package/index.js +4 -0
- package/jest.config.mjs +201 -0
- package/package.json +36 -0
- package/scss/Services/_notification.scss +0 -0
- package/scss/index.scss +2 -0
- package/src/Client.js +39 -0
- package/src/api/index.js +20 -0
- package/src/api/v1/Accounts.js +22 -0
- package/src/api/v1/Auth.js +15 -0
- package/src/api/v1/Categories.js +12 -0
- package/src/api/v1/Changelogs.js +11 -0
- package/src/api/v1/Configs.js +12 -0
- package/src/api/v1/ContactForms.js +12 -0
- package/src/api/v1/ConversationalTopics.js +12 -0
- package/src/api/v1/Countries.js +9 -0
- package/src/api/v1/Coupons.js +12 -0
- package/src/api/v1/Courses.js +81 -0
- package/src/api/v1/Currencies.js +10 -0
- package/src/api/v1/Files.js +10 -0
- package/src/api/v1/Forums.js +24 -0
- package/src/api/v1/Hashes.js +11 -0
- package/src/api/v1/Insignias.js +12 -0
- package/src/api/v1/Languages.js +12 -0
- package/src/api/v1/MailBlacklist.js +11 -0
- package/src/api/v1/Organizations.js +11 -0
- package/src/api/v1/Quizzes.js +32 -0
- package/src/api/v1/ShortLinks.js +12 -0
- package/src/api/v1/Surveys.js +32 -0
- package/src/api/v1/Tags.js +12 -0
- package/src/api/v1/Taxes.js +12 -0
- package/src/api/v1/Teacher.js +37 -0
- package/src/api/v1/Translations.js +12 -0
- package/src/api/v1/UserTypes.js +12 -0
- package/src/api/v1/Users.js +82 -0
- package/src/api/v1/Zoom.js +23 -0
- package/src/api/v1/index.js +74 -0
- package/src/index.js +21 -0
- package/tests/api/v1.test.js +480 -0
- package/tests/client.test.js +214 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import InsigniaClient from '../src/Client.js';
|
|
2
|
+
|
|
3
|
+
const BASE = 'http://localhost:8000';
|
|
4
|
+
|
|
5
|
+
function mockFetch(json = {}) {
|
|
6
|
+
return jest.fn().mockResolvedValue({ json: () => Promise.resolve(json) });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
delete process.env.INSIGNIA_EDUCATION_API_BASE_URL;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
delete global.fetch;
|
|
15
|
+
delete process.env.INSIGNIA_EDUCATION_API_BASE_URL;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// ─── baseUrl resolution ───────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
describe('baseUrl resolution', () => {
|
|
21
|
+
test('uses explicit baseUrl when provided', async () => {
|
|
22
|
+
global.fetch = mockFetch();
|
|
23
|
+
const client = new InsigniaClient('https://custom.example.com');
|
|
24
|
+
await client.get('/test');
|
|
25
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
26
|
+
'https://custom.example.com/test',
|
|
27
|
+
expect.any(Object)
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('strips trailing slash from explicit baseUrl', async () => {
|
|
32
|
+
global.fetch = mockFetch();
|
|
33
|
+
const client = new InsigniaClient('https://custom.example.com/');
|
|
34
|
+
await client.get('/test');
|
|
35
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
36
|
+
'https://custom.example.com/test',
|
|
37
|
+
expect.any(Object)
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('uses INSIGNIA_EDUCATION_API_BASE_URL env var when baseUrl is null', async () => {
|
|
42
|
+
process.env.INSIGNIA_EDUCATION_API_BASE_URL = 'https://env.example.com';
|
|
43
|
+
global.fetch = mockFetch();
|
|
44
|
+
const client = new InsigniaClient(null);
|
|
45
|
+
await client.get('/test');
|
|
46
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
47
|
+
'https://env.example.com/test',
|
|
48
|
+
expect.any(Object)
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('falls back to https://insigniaeducation.com when baseUrl is null and env var is not set', async () => {
|
|
53
|
+
global.fetch = mockFetch();
|
|
54
|
+
const client = new InsigniaClient(null);
|
|
55
|
+
await client.get('/test');
|
|
56
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
57
|
+
'https://insigniaeducation.com/test',
|
|
58
|
+
expect.any(Object)
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('falls back to default when constructed with no arguments', async () => {
|
|
63
|
+
global.fetch = mockFetch();
|
|
64
|
+
const client = new InsigniaClient();
|
|
65
|
+
await client.get('/test');
|
|
66
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
67
|
+
'https://insigniaeducation.com/test',
|
|
68
|
+
expect.any(Object)
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('explicit baseUrl takes precedence over env var', async () => {
|
|
73
|
+
process.env.INSIGNIA_EDUCATION_API_BASE_URL = 'https://env.example.com';
|
|
74
|
+
global.fetch = mockFetch();
|
|
75
|
+
const client = new InsigniaClient('https://explicit.example.com');
|
|
76
|
+
await client.get('/test');
|
|
77
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
78
|
+
'https://explicit.example.com/test',
|
|
79
|
+
expect.any(Object)
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// ─── token management ────────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
describe('token management', () => {
|
|
87
|
+
test('getToken returns null by default', () => {
|
|
88
|
+
const client = new InsigniaClient();
|
|
89
|
+
expect(client.getToken()).toBeNull();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('getToken returns token passed to constructor', () => {
|
|
93
|
+
const client = new InsigniaClient(null, 'my-token');
|
|
94
|
+
expect(client.getToken()).toBe('my-token');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('setToken updates the token', () => {
|
|
98
|
+
const client = new InsigniaClient();
|
|
99
|
+
client.setToken('new-token');
|
|
100
|
+
expect(client.getToken()).toBe('new-token');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('Authorization header is set when token is present', async () => {
|
|
104
|
+
global.fetch = mockFetch();
|
|
105
|
+
const client = new InsigniaClient(null, 'bearer-token');
|
|
106
|
+
await client.get('/test');
|
|
107
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
108
|
+
expect(options.headers['Authorization']).toBe('Bearer bearer-token');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('Authorization header is absent when no token', async () => {
|
|
112
|
+
global.fetch = mockFetch();
|
|
113
|
+
const client = new InsigniaClient();
|
|
114
|
+
await client.get('/test');
|
|
115
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
116
|
+
expect(options.headers['Authorization']).toBeUndefined();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('Authorization header updates after setToken', async () => {
|
|
120
|
+
global.fetch = mockFetch();
|
|
121
|
+
const client = new InsigniaClient();
|
|
122
|
+
client.setToken('updated-token');
|
|
123
|
+
await client.get('/test');
|
|
124
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
125
|
+
expect(options.headers['Authorization']).toBe('Bearer updated-token');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// ─── HTTP methods ─────────────────────────────────────────────────────────────
|
|
130
|
+
|
|
131
|
+
describe('HTTP methods', () => {
|
|
132
|
+
let client;
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
global.fetch = mockFetch({ ok: true });
|
|
136
|
+
client = new InsigniaClient(BASE);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('get() sends GET with no body', async () => {
|
|
140
|
+
await client.get('/path');
|
|
141
|
+
const [url, options] = global.fetch.mock.calls[0];
|
|
142
|
+
expect(url).toBe(`${BASE}/path`);
|
|
143
|
+
expect(options.method).toBe('GET');
|
|
144
|
+
expect(options.body).toBeUndefined();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('post() sends POST with body', async () => {
|
|
148
|
+
await client.post('/path', { key: 'val' });
|
|
149
|
+
const [url, options] = global.fetch.mock.calls[0];
|
|
150
|
+
expect(url).toBe(`${BASE}/path`);
|
|
151
|
+
expect(options.method).toBe('POST');
|
|
152
|
+
expect(options.body).toBe(JSON.stringify({ key: 'val' }));
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('post() sends POST with no body when not provided', async () => {
|
|
156
|
+
await client.post('/path');
|
|
157
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
158
|
+
expect(options.method).toBe('POST');
|
|
159
|
+
expect(options.body).toBeUndefined();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('put() sends PUT with body', async () => {
|
|
163
|
+
await client.put('/path', { key: 'val' });
|
|
164
|
+
const [url, options] = global.fetch.mock.calls[0];
|
|
165
|
+
expect(url).toBe(`${BASE}/path`);
|
|
166
|
+
expect(options.method).toBe('PUT');
|
|
167
|
+
expect(options.body).toBe(JSON.stringify({ key: 'val' }));
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('put() sends PUT with no body when not provided', async () => {
|
|
171
|
+
await client.put('/path');
|
|
172
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
173
|
+
expect(options.method).toBe('PUT');
|
|
174
|
+
expect(options.body).toBeUndefined();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('patch() sends PATCH with body', async () => {
|
|
178
|
+
await client.patch('/path', { key: 'val' });
|
|
179
|
+
const [url, options] = global.fetch.mock.calls[0];
|
|
180
|
+
expect(url).toBe(`${BASE}/path`);
|
|
181
|
+
expect(options.method).toBe('PATCH');
|
|
182
|
+
expect(options.body).toBe(JSON.stringify({ key: 'val' }));
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('patch() sends PATCH with no body when not provided', async () => {
|
|
186
|
+
await client.patch('/path');
|
|
187
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
188
|
+
expect(options.method).toBe('PATCH');
|
|
189
|
+
expect(options.body).toBeUndefined();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('del() sends DELETE with no body', async () => {
|
|
193
|
+
await client.del('/path');
|
|
194
|
+
const [url, options] = global.fetch.mock.calls[0];
|
|
195
|
+
expect(url).toBe(`${BASE}/path`);
|
|
196
|
+
expect(options.method).toBe('DELETE');
|
|
197
|
+
expect(options.body).toBeUndefined();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('Content-Type is always application/json', async () => {
|
|
201
|
+
await client.get('/path');
|
|
202
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
203
|
+
expect(options.headers['Content-Type']).toBe('application/json');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('returns parsed JSON from response', async () => {
|
|
207
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
208
|
+
json: () => Promise.resolve({ id: 1, name: 'test' }),
|
|
209
|
+
});
|
|
210
|
+
client = new InsigniaClient(BASE);
|
|
211
|
+
const result = await client.get('/path');
|
|
212
|
+
expect(result).toEqual({ id: 1, name: 'test' });
|
|
213
|
+
});
|
|
214
|
+
});
|