@insignia-education/api-sdk-js 0.9.22 → 0.9.24

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.
Files changed (163) hide show
  1. package/.env +1 -0
  2. package/.env.test +5 -0
  3. package/.github/workflows/npm-publish-github-packages.yml +0 -0
  4. package/LICENSE +0 -0
  5. package/README.md +0 -14
  6. package/babel.config.cjs +0 -0
  7. package/coverage/clover.xml +860 -0
  8. package/coverage/coverage-final.json +33 -0
  9. package/coverage/lcov-report/Accounts.js.html +151 -0
  10. package/coverage/lcov-report/Auth.js.html +130 -0
  11. package/coverage/lcov-report/Categories.js.html +121 -0
  12. package/coverage/lcov-report/Changelogs.js.html +118 -0
  13. package/coverage/lcov-report/Client.js.html +349 -0
  14. package/coverage/lcov-report/Configs.js.html +121 -0
  15. package/coverage/lcov-report/ContactForms.js.html +121 -0
  16. package/coverage/lcov-report/ConversationalTopics.js.html +121 -0
  17. package/coverage/lcov-report/Countries.js.html +112 -0
  18. package/coverage/lcov-report/Coupons.js.html +121 -0
  19. package/coverage/lcov-report/Courses.js.html +328 -0
  20. package/coverage/lcov-report/Currencies.js.html +115 -0
  21. package/coverage/lcov-report/Files.js.html +115 -0
  22. package/coverage/lcov-report/Forums.js.html +157 -0
  23. package/coverage/lcov-report/Hashes.js.html +118 -0
  24. package/coverage/lcov-report/Insignias.js.html +121 -0
  25. package/coverage/lcov-report/Languages.js.html +121 -0
  26. package/coverage/lcov-report/MailBlacklist.js.html +118 -0
  27. package/coverage/lcov-report/Organizations.js.html +118 -0
  28. package/coverage/lcov-report/Quizzes.js.html +181 -0
  29. package/coverage/lcov-report/ShortLinks.js.html +121 -0
  30. package/coverage/lcov-report/Surveys.js.html +181 -0
  31. package/coverage/lcov-report/Tags.js.html +121 -0
  32. package/coverage/lcov-report/Taxes.js.html +121 -0
  33. package/coverage/lcov-report/Teacher.js.html +196 -0
  34. package/coverage/lcov-report/Translations.js.html +121 -0
  35. package/coverage/lcov-report/UserTypes.js.html +121 -0
  36. package/coverage/lcov-report/Users.js.html +331 -0
  37. package/coverage/lcov-report/Zoom.js.html +154 -0
  38. package/coverage/lcov-report/base.css +224 -0
  39. package/coverage/lcov-report/block-navigation.js +87 -0
  40. package/coverage/lcov-report/favicon.png +0 -0
  41. package/coverage/lcov-report/index.html +161 -0
  42. package/coverage/lcov-report/prettify.css +1 -0
  43. package/coverage/lcov-report/prettify.js +2 -0
  44. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  45. package/coverage/lcov-report/sorter.js +210 -0
  46. package/coverage/lcov-report/src/Client.js.html +349 -0
  47. package/coverage/lcov-report/src/api/index.html +116 -0
  48. package/coverage/lcov-report/src/api/index.js.html +127 -0
  49. package/coverage/lcov-report/src/api/v1/Accounts.js.html +151 -0
  50. package/coverage/lcov-report/src/api/v1/Auth.js.html +130 -0
  51. package/coverage/lcov-report/src/api/v1/Categories.js.html +121 -0
  52. package/coverage/lcov-report/src/api/v1/Changelogs.js.html +118 -0
  53. package/coverage/lcov-report/src/api/v1/Configs.js.html +121 -0
  54. package/coverage/lcov-report/src/api/v1/ContactForms.js.html +121 -0
  55. package/coverage/lcov-report/src/api/v1/ConversationalTopics.js.html +121 -0
  56. package/coverage/lcov-report/src/api/v1/Countries.js.html +112 -0
  57. package/coverage/lcov-report/src/api/v1/Coupons.js.html +121 -0
  58. package/coverage/lcov-report/src/api/v1/Courses.js.html +355 -0
  59. package/coverage/lcov-report/src/api/v1/Currencies.js.html +115 -0
  60. package/coverage/lcov-report/src/api/v1/Files.js.html +115 -0
  61. package/coverage/lcov-report/src/api/v1/Forums.js.html +157 -0
  62. package/coverage/lcov-report/src/api/v1/Hashes.js.html +118 -0
  63. package/coverage/lcov-report/src/api/v1/Insignias.js.html +121 -0
  64. package/coverage/lcov-report/src/api/v1/Languages.js.html +121 -0
  65. package/coverage/lcov-report/src/api/v1/MailBlacklist.js.html +118 -0
  66. package/coverage/lcov-report/src/api/v1/Organizations.js.html +118 -0
  67. package/coverage/lcov-report/src/api/v1/PaymentMethods.js.html +112 -0
  68. package/coverage/lcov-report/src/api/v1/Quizzes.js.html +181 -0
  69. package/coverage/lcov-report/src/api/v1/ShortLinks.js.html +121 -0
  70. package/coverage/lcov-report/src/api/v1/Surveys.js.html +181 -0
  71. package/coverage/lcov-report/src/api/v1/Tags.js.html +121 -0
  72. package/coverage/lcov-report/src/api/v1/Taxes.js.html +121 -0
  73. package/coverage/lcov-report/src/api/v1/Teacher.js.html +196 -0
  74. package/coverage/lcov-report/src/api/v1/Translations.js.html +121 -0
  75. package/coverage/lcov-report/src/api/v1/UserTypes.js.html +121 -0
  76. package/coverage/lcov-report/src/api/v1/Users.js.html +334 -0
  77. package/coverage/lcov-report/src/api/v1/Zoom.js.html +124 -0
  78. package/coverage/lcov-report/src/api/v1/index.html +521 -0
  79. package/coverage/lcov-report/src/api/v1/index.js.html +295 -0
  80. package/coverage/lcov-report/src/index.html +131 -0
  81. package/coverage/lcov-report/src/index.js.html +109 -0
  82. package/coverage/lcov-report/tests/helpers.js.html +130 -0
  83. package/coverage/lcov-report/tests/index.html +116 -0
  84. package/coverage/lcov-report/tests/integration/cookieJar.js.html +229 -0
  85. package/coverage/lcov-report/tests/integration/index.html +116 -0
  86. package/coverage/lcov.info +1606 -0
  87. package/coverage/test-report.html +980 -0
  88. package/eslint.config.mjs +10 -0
  89. package/index.js +0 -0
  90. package/jest.config.mjs +10 -0
  91. package/package.json +1 -1
  92. package/scss/Services/_notification.scss +0 -0
  93. package/scss/index.scss +0 -0
  94. package/src/Client.js +55 -2
  95. package/src/api/index.js +0 -0
  96. package/src/api/v1/Accounts.js +0 -0
  97. package/src/api/v1/Auth.js +0 -0
  98. package/src/api/v1/Categories.js +0 -0
  99. package/src/api/v1/Changelogs.js +0 -0
  100. package/src/api/v1/Configs.js +0 -0
  101. package/src/api/v1/ContactForms.js +0 -0
  102. package/src/api/v1/ConversationalTopics.js +0 -0
  103. package/src/api/v1/Countries.js +0 -0
  104. package/src/api/v1/Coupons.js +0 -0
  105. package/src/api/v1/Courses.js +10 -1
  106. package/src/api/v1/Currencies.js +0 -0
  107. package/src/api/v1/Files.js +0 -0
  108. package/src/api/v1/Forums.js +0 -0
  109. package/src/api/v1/Hashes.js +0 -0
  110. package/src/api/v1/Insignias.js +0 -0
  111. package/src/api/v1/Languages.js +0 -0
  112. package/src/api/v1/MailBlacklist.js +0 -0
  113. package/src/api/v1/Organizations.js +0 -0
  114. package/src/api/v1/PaymentMethods.js +0 -0
  115. package/src/api/v1/Quizzes.js +0 -0
  116. package/src/api/v1/ShortLinks.js +0 -0
  117. package/src/api/v1/Surveys.js +0 -0
  118. package/src/api/v1/Taxes.js +0 -0
  119. package/src/api/v1/Teacher.js +0 -0
  120. package/src/api/v1/UserTypes.js +0 -0
  121. package/src/api/v1/Users.js +0 -0
  122. package/src/api/v1/Zoom.js +0 -10
  123. package/src/api/v1/index.js +1 -4
  124. package/src/index.js +0 -0
  125. package/tests/client.test.js +64 -1
  126. package/tests/helpers.js +16 -0
  127. package/tests/integration/api/v1/accounts.test.js +37 -0
  128. package/tests/integration/api/v1/auth/login.test.js +60 -0
  129. package/tests/integration/api/v1/categories.test.js +19 -0
  130. package/tests/integration/api/v1/changelogs.test.js +21 -0
  131. package/tests/integration/api/v1/configs.test.js +20 -0
  132. package/tests/integration/api/v1/contact-forms.test.js +24 -0
  133. package/tests/integration/api/v1/conversational-topics.test.js +19 -0
  134. package/tests/integration/api/v1/countries.test.js +20 -0
  135. package/tests/integration/api/v1/coupons.test.js +26 -0
  136. package/tests/integration/api/v1/courses/by-cod.test.js +19 -0
  137. package/tests/integration/api/v1/courses/index.test.js +46 -0
  138. package/tests/integration/api/v1/currencies/index.test.js +24 -0
  139. package/tests/integration/api/v1/currencies/values.test.js +24 -0
  140. package/tests/integration/api/v1/files.test.js +25 -0
  141. package/tests/integration/api/v1/forums/index.test.js +23 -0
  142. package/tests/integration/api/v1/hashes.test.js +26 -0
  143. package/tests/integration/api/v1/insignias.test.js +19 -0
  144. package/tests/integration/api/v1/languages.test.js +28 -0
  145. package/tests/integration/api/v1/mail-blacklist.test.js +26 -0
  146. package/tests/integration/api/v1/organizations.test.js +25 -0
  147. package/tests/integration/api/v1/payment-methods/by-currencies.test.js +51 -0
  148. package/tests/integration/api/v1/quizzes/index.test.js +39 -0
  149. package/tests/integration/api/v1/short-links.test.js +27 -0
  150. package/tests/integration/api/v1/surveys/index.test.js +40 -0
  151. package/tests/integration/api/v1/taxes.test.js +20 -0
  152. package/tests/integration/api/v1/teacher/index.test.js +53 -0
  153. package/tests/integration/api/v1/user-types.test.js +19 -0
  154. package/tests/integration/api/v1/users/cash-receivers.test.js +19 -0
  155. package/tests/integration/api/v1/users/index.test.js +35 -0
  156. package/tests/integration/api/v1/zoom.test.js +24 -0
  157. package/tests/integration/loadEnv.js +0 -0
  158. package/src/api/v1/Tags.js +0 -12
  159. package/src/api/v1/Translations.js +0 -12
  160. package/tests/api/v1.test.js +0 -480
  161. package/tests/integration/api.v1.test.js +0 -125
  162. package/tests/integration/auth.test.js +0 -40
  163. package/tests/integration/cookieJar.js +0 -48
package/eslint.config.mjs CHANGED
@@ -16,4 +16,14 @@ export default [
16
16
  "no-console": "warn",
17
17
  },
18
18
  },
19
+ {
20
+ files: ["tests/**/*.js"],
21
+ languageOptions: {
22
+ globals: {
23
+ ...globals.node,
24
+ ...globals.jest,
25
+ fetch: "readonly",
26
+ },
27
+ },
28
+ },
19
29
  ];
package/index.js CHANGED
File without changes
package/jest.config.mjs CHANGED
@@ -4,6 +4,16 @@ const config = {
4
4
  coverageDirectory: 'coverage',
5
5
  coverageProvider: 'v8',
6
6
 
7
+ reporters: [
8
+ 'default',
9
+ ['jest-html-reporter', {
10
+ outputPath: 'coverage/test-report.html',
11
+ pageTitle: 'API SDK Test Report',
12
+ includeFailureMsg: true,
13
+ includeConsoleLog: true,
14
+ }],
15
+ ],
16
+
7
17
  projects: [
8
18
  {
9
19
  displayName: 'unit',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insignia-education/api-sdk-js",
3
- "version": "0.9.22",
3
+ "version": "0.9.24",
4
4
  "description": "JavaScript SDK for the Insignia Education API",
5
5
  "main": "index.js",
6
6
  "type": "module",
File without changes
package/scss/index.scss CHANGED
File without changes
package/src/Client.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export default class InsigniaClient {
2
2
  #baseUrl;
3
+ #cookies = new Map();
3
4
 
4
5
  constructor(baseUrl) {
5
6
  this.#baseUrl = InsigniaClient._resolve(baseUrl);
@@ -16,14 +17,66 @@ export default class InsigniaClient {
16
17
  }
17
18
 
18
19
  #headers() {
19
- return { 'Content-Type': 'application/json' };
20
+ const headers = {
21
+ 'Accept': 'application/json',
22
+ 'Content-Type': 'application/json',
23
+ };
24
+
25
+ const cookie = this.#cookieHeader();
26
+ if (cookie) headers.Cookie = cookie;
27
+
28
+ return headers;
29
+ }
30
+
31
+ #cookieHeader() {
32
+ if (typeof window !== 'undefined' || this.#cookies.size === 0) return null;
33
+
34
+ return Array.from(this.#cookies.entries())
35
+ .map(([name, value]) => `${name}=${value}`)
36
+ .join('; ');
37
+ }
38
+
39
+ #storeCookies(response) {
40
+ if (typeof window !== 'undefined') return;
41
+
42
+ const headers = response.headers;
43
+ const setCookies = typeof headers?.getSetCookie === 'function'
44
+ ? headers.getSetCookie()
45
+ : [headers?.get?.('set-cookie')].filter(Boolean);
46
+
47
+ for (const setCookie of setCookies) {
48
+ const [pair] = setCookie.split(';');
49
+ const separator = pair.indexOf('=');
50
+ if (separator === -1) continue;
51
+
52
+ this.#cookies.set(pair.slice(0, separator), pair.slice(separator + 1));
53
+ }
54
+ }
55
+
56
+ async #parseResponse(response) {
57
+ if ([204, 205].includes(response.status)) return null;
58
+
59
+ try {
60
+ if (typeof response.text === 'function') {
61
+ const text = await response.text();
62
+ return text === '' ? null : JSON.parse(text);
63
+ }
64
+
65
+ return await response.json();
66
+ } catch (error) {
67
+ if (error instanceof SyntaxError && error.message.includes('Unexpected end')) {
68
+ return null;
69
+ }
70
+ throw error;
71
+ }
20
72
  }
21
73
 
22
74
  async #request(method, path, body = null) {
23
75
  const options = { method, headers: this.#headers(), credentials: 'include' };
24
76
  if (body !== null) options.body = JSON.stringify(body);
25
77
  const response = await fetch(`${this.#baseUrl}${path}`, options);
26
- const data = await response.json();
78
+ this.#storeCookies(response);
79
+ const data = await this.#parseResponse(response);
27
80
  return data?.success ? data.response : data;
28
81
  }
29
82
 
package/src/api/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -5,7 +5,16 @@ export default class Courses {
5
5
  this.#client = client;
6
6
  }
7
7
 
8
- get(id = null) { return id ? this.#client.get(`/courses/${id}`) : this.#client.get('/courses'); }
8
+ getByCod(cod) { return this.#client.get(`/courses/cod/${cod}`); }
9
+
10
+ get(id = null, { page = 1, perPage = 15 } = {}) {
11
+ if (id) return this.#client.get(`/courses/${id}`);
12
+ const params = new URLSearchParams();
13
+ if (page) params.set('page', page);
14
+ if (perPage) params.set('per_page', perPage);
15
+ const qs = params.toString();
16
+ return this.#client.get(qs ? `/courses?${qs}` : '/courses');
17
+ }
9
18
  create(data) { return this.#client.put('/courses', data); }
10
19
  edit(id, data) { return this.#client.patch(`/courses/${id}`, data); }
11
20
  delete(id) { return this.#client.del(`/courses/${id}`); }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -10,14 +10,4 @@ export default class Zoom {
10
10
  get: (id = null) => id ? this.#client.get(`/zoom/meetings/${id}`) : this.#client.get('/zoom/meetings'),
11
11
  };
12
12
  }
13
-
14
- tokens() {
15
- const base = '/zoom/tokens';
16
- return {
17
- get: (id = null) => id ? this.#client.get(`${base}/${id}`) : this.#client.get(base),
18
- create: (data) => this.#client.put(base, data),
19
- edit: (id, data) => this.#client.patch(`${base}/${id}`, data),
20
- delete: (id) => this.#client.del(`${base}/${id}`),
21
- };
22
- }
23
13
  }
@@ -21,10 +21,8 @@ import PaymentMethods from './PaymentMethods.js';
21
21
  import Quizzes from './Quizzes.js';
22
22
  import ShortLinks from './ShortLinks.js';
23
23
  import Surveys from './Surveys.js';
24
- import Tags from './Tags.js';
25
24
  import Taxes from './Taxes.js';
26
25
  import Teacher from './Teacher.js';
27
- import Translations from './Translations.js';
28
26
  import UserTypes from './UserTypes.js';
29
27
  import Users from './Users.js';
30
28
  import Zoom from './Zoom.js';
@@ -36,6 +34,7 @@ export default class InsigniaApiV1 extends InsigniaApi {
36
34
  baseUrl += !/\/v1(\/|$)/.test(baseUrl) ? '/v1' : '';
37
35
  return baseUrl;
38
36
  }
37
+
39
38
  constructor(baseUrl = null) {
40
39
  let url = InsigniaApiV1._resolve(baseUrl);
41
40
  super(url);
@@ -62,10 +61,8 @@ export default class InsigniaApiV1 extends InsigniaApi {
62
61
  this.quizzes = new Quizzes(this);
63
62
  this.shortLinks = new ShortLinks(this);
64
63
  this.surveys = new Surveys(this);
65
- this.tags = new Tags(this);
66
64
  this.taxes = new Taxes(this);
67
65
  this.teacher = new Teacher(this);
68
- this.translations = new Translations(this);
69
66
  this.userTypes = new UserTypes(this);
70
67
  this.users = new Users(this);
71
68
  this.zoom = new Zoom(this);
package/src/index.js CHANGED
File without changes
@@ -79,6 +79,19 @@ describe('baseUrl resolution', () => {
79
79
  expect.any(Object)
80
80
  );
81
81
  });
82
+
83
+ test('falls back to default when process is undefined', async () => {
84
+ const saved = global.process;
85
+ global.process = undefined;
86
+ global.fetch = mockFetch();
87
+ const client = new InsigniaClient(null);
88
+ await client.get('/test');
89
+ expect(global.fetch).toHaveBeenCalledWith(
90
+ 'https://insigniaeducation.com/test',
91
+ expect.any(Object)
92
+ );
93
+ global.process = saved;
94
+ });
82
95
  });
83
96
 
84
97
  // ─── HTTP methods ─────────────────────────────────────────────────────────────
@@ -152,9 +165,10 @@ describe('HTTP methods', () => {
152
165
  expect(options.body).toBeUndefined();
153
166
  });
154
167
 
155
- test('Content-Type is always application/json', async () => {
168
+ test('JSON headers are always sent', async () => {
156
169
  await client.get('/path');
157
170
  const [, options] = global.fetch.mock.calls[0];
171
+ expect(options.headers.Accept).toBe('application/json');
158
172
  expect(options.headers['Content-Type']).toBe('application/json');
159
173
  });
160
174
 
@@ -164,6 +178,26 @@ describe('HTTP methods', () => {
164
178
  expect(options.credentials).toBe('include');
165
179
  });
166
180
 
181
+ test('stores response cookies and sends them on later requests in Node', async () => {
182
+ global.fetch = jest.fn()
183
+ .mockResolvedValueOnce({
184
+ headers: {
185
+ getSetCookie: () => ['token=abc123; Path=/; HttpOnly; Secure; SameSite=Lax'],
186
+ },
187
+ json: () => Promise.resolve({ success: 'ok' }),
188
+ })
189
+ .mockResolvedValueOnce({
190
+ json: () => Promise.resolve({ id: 1, title: 'test' }),
191
+ });
192
+ client = new InsigniaClient(BASE);
193
+
194
+ await client.post('/auth/login', { email: 'admin@example.com', password: 'secret' });
195
+ await client.get('/accounts');
196
+
197
+ const [, options] = global.fetch.mock.calls[1];
198
+ expect(options.headers.Cookie).toBe('token=abc123');
199
+ });
200
+
167
201
  test('returns parsed JSON from response', async () => {
168
202
  global.fetch = jest.fn().mockResolvedValue({
169
203
  json: () => Promise.resolve({ id: 1, name: 'test' }),
@@ -172,4 +206,33 @@ describe('HTTP methods', () => {
172
206
  const result = await client.get('/path');
173
207
  expect(result).toEqual({ id: 1, name: 'test' });
174
208
  });
209
+
210
+ test('returns null for empty response text', async () => {
211
+ global.fetch = jest.fn().mockResolvedValue({
212
+ status: 200,
213
+ text: () => Promise.resolve(''),
214
+ });
215
+ client = new InsigniaClient(BASE);
216
+ const result = await client.get('/path');
217
+ expect(result).toBeNull();
218
+ });
219
+
220
+ test('returns null for no-content responses', async () => {
221
+ global.fetch = jest.fn().mockResolvedValue({
222
+ status: 204,
223
+ json: jest.fn(),
224
+ });
225
+ client = new InsigniaClient(BASE);
226
+ const result = await client.del('/path');
227
+ expect(result).toBeNull();
228
+ });
229
+
230
+ test('returns null when json parsing fails because the response is empty', async () => {
231
+ global.fetch = jest.fn().mockResolvedValue({
232
+ json: () => Promise.reject(new SyntaxError('Unexpected end of JSON input')),
233
+ });
234
+ client = new InsigniaClient(BASE);
235
+ const result = await client.get('/path');
236
+ expect(result).toBeNull();
237
+ });
175
238
  });
@@ -0,0 +1,16 @@
1
+ import InsigniaApiV1 from '../src/api/v1/index.js';
2
+
3
+ export const api = new InsigniaApiV1(process.env.INSIGNIA_EDUCATION_API_BASE_URL);
4
+
5
+ export const loginCustomer = () => api.auth.login({
6
+ email: process.env.TEST_EMAIL,
7
+ password: process.env.TEST_PASSWORD,
8
+ });
9
+
10
+ export const loginAdmin = () => api.auth.login({
11
+ email: process.env.TEST_EMAIL_ADMIN,
12
+ password: process.env.TEST_PASSWORD_ADMIN,
13
+ });
14
+
15
+
16
+ export const logout = () => api.auth.logout();
@@ -0,0 +1,37 @@
1
+ import {
2
+ api,
3
+ loginCustomer,
4
+ loginAdmin
5
+ } from '../../../helpers.js';
6
+
7
+ describe('api/v1/accounts', () => {
8
+ test('get | unauthenticated', async () => {
9
+ await api.accounts.get()
10
+ .then(response => {
11
+ expect(response.success).toBe(false);
12
+ expect(response.status).toBe(401);
13
+ });
14
+ });
15
+ test('get | authenticated but other type', async () => {
16
+ await loginCustomer();
17
+ await api.accounts.get()
18
+ .then(response => {
19
+ console.log(response);
20
+ expect(response.success).toBe(false);
21
+ expect(response.status).toBe(403);
22
+ });
23
+ });
24
+ test('get | authenticated', async () => {
25
+ await loginAdmin();
26
+ await api.accounts.get()
27
+ .then(response => {
28
+ response = Object.values(response);
29
+ expect(response.length > 0).toBe(true);
30
+ response.forEach(account => {
31
+ expect(account["id"]).toBeDefined();
32
+ expect(account["cod"]).toBeDefined();
33
+ expect(account["title"]).toBeDefined();
34
+ });
35
+ });
36
+ });
37
+ });
@@ -0,0 +1,60 @@
1
+ import {
2
+ api,
3
+ loginCustomer,
4
+ loginAdmin,
5
+ logout,
6
+ } from '../../../../helpers.js';
7
+
8
+
9
+
10
+
11
+ describe('api/v1/auth/login', () => {
12
+ test('POST | failure | no email validation', async () => {
13
+ const password = process.env.TEST_PASSWORD;
14
+ logout()
15
+ .then(() => api.auth.login({ password })
16
+ .then(response => {
17
+ // here we have more info of the request because we have the errors
18
+ expect(response["success"]).toBeDefined();
19
+ expect(response["status"]).toBeDefined();
20
+ expect(response["status"]).toBe(422);
21
+ expect(response["errors"]).toBeDefined();
22
+ expect(Object.values(response["errors"]).length > 0).toBe(true);
23
+ expect(response["errors"]["email"]).toBeDefined();
24
+ }));
25
+ });
26
+
27
+ test('POST | failure | no password validation', async () => {
28
+ const email = process.env.TEST_EMAIL;
29
+ logout()
30
+ .then(() => api.auth.login({ email })
31
+ .then(response => {
32
+ // here we have more info of the request because we have the errors
33
+ expect(response["success"]).toBeDefined();
34
+ expect(response["errors"]).toBeDefined();
35
+ expect(response["status"]).toBeDefined();
36
+ expect(response["status"]).toBe(422);
37
+ expect(Object.values(response["errors"]).length > 0).toBe(true);
38
+ expect(response["errors"]["password"]).toBeDefined();
39
+ }));
40
+
41
+ });
42
+
43
+ test('POST | success', async () => {
44
+ logout()
45
+ .then(() => loginAdmin()
46
+ .then(response => {
47
+ expect(response["success"]).toBeDefined();
48
+ expect(response["success"]).toBe("ok");
49
+ }));
50
+ });
51
+
52
+ test('POST | double login', async () => {
53
+ loginAdmin()
54
+ .then(() => loginAdmin()
55
+ .then(response => {
56
+ expect(response["success"]).toBeDefined();
57
+ expect(response["success"]).toBe("ok");
58
+ }));
59
+ });
60
+ });
@@ -0,0 +1,19 @@
1
+ import {
2
+ api
3
+ } from '../../../helpers.js';
4
+
5
+ describe('api/v1/categories', () => {
6
+ test('get', async () => {
7
+ await api.categories.get()
8
+ .then(response => {
9
+ response = Object.values(response);
10
+ expect(response.length > 0).toBe(true);
11
+ response.forEach(category => {
12
+ expect(category["id"]).toBeDefined();
13
+ expect(category["cod"]).toBeDefined();
14
+ expect(category["title"]).toBeDefined();
15
+ expect(category["enabled"]).toBeDefined();
16
+ });
17
+ });
18
+ });
19
+ });
@@ -0,0 +1,21 @@
1
+ import {
2
+ api,
3
+ loginCustomer,
4
+ loginAdmin
5
+ } from '../../../helpers.js';
6
+
7
+ describe('api/v1/changelogs', () => {
8
+ test('get | authenticated', async () => {
9
+ await loginAdmin();
10
+ await api.changelogs.get()
11
+ .then(response => {
12
+ response = Object.values(response);
13
+ expect(Array.isArray(response)).toBe(true);
14
+ response.forEach(changelog => {
15
+ expect(changelog["id"]).toBeDefined();
16
+ expect(changelog["created_at"]).toBeDefined();
17
+ expect(changelog["updated_at"]).toBeDefined();
18
+ });
19
+ });
20
+ });
21
+ });
@@ -0,0 +1,20 @@
1
+ import {
2
+ api,
3
+ loginCustomer,
4
+ loginAdmin
5
+ } from '../../../helpers.js';
6
+
7
+ describe('api/v1/configs', () => {
8
+ test('get', async () => {
9
+ await api.configs.get()
10
+ .then(response => {
11
+ response = Object.values(response);
12
+ expect(response.length > 0).toBe(true);
13
+ response.forEach(config => {
14
+ expect(config["id"]).toBeDefined();
15
+ expect(config["cod"]).toBeDefined();
16
+ expect(config["value"]).toBeDefined();
17
+ });
18
+ });
19
+ });
20
+ });
@@ -0,0 +1,24 @@
1
+ import {
2
+ api,
3
+ loginCustomer,
4
+ loginAdmin
5
+ } from '../../../helpers.js';
6
+
7
+
8
+ describe('api/v1/contact-forms', () => {
9
+ test('get | authenticated', async () => {
10
+ await loginAdmin();
11
+ await api.contactForms.get()
12
+ .then(response => {
13
+ response = Object.values(response);
14
+ expect(Array.isArray(response)).toBe(true);
15
+ response.forEach(form => {
16
+ expect(form["id"]).toBeDefined();
17
+ expect(form["name"]).toBeDefined();
18
+ expect(form["email"]).toBeDefined();
19
+ expect(form["message"]).toBeDefined();
20
+ expect(form["created_at"]).toBeDefined();
21
+ });
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,19 @@
1
+ import InsigniaApiV1 from '../../../../src/api/v1/index.js';
2
+
3
+ const api = new InsigniaApiV1(process.env.INSIGNIA_EDUCATION_API_BASE_URL);
4
+
5
+ describe('api/v1/conversational-topics', () => {
6
+ test('get', async () => {
7
+ await api.conversationalTopics.get()
8
+ .then(response => {
9
+ response = Object.values(response);
10
+ expect(response.length > 0).toBe(true);
11
+ response.forEach(topic => {
12
+ expect(topic["id"]).toBeDefined();
13
+ expect(topic["cod"]).toBeDefined();
14
+ expect(topic["title"]).toBeDefined();
15
+ expect(topic["enabled"]).toBeDefined();
16
+ });
17
+ });
18
+ });
19
+ });
@@ -0,0 +1,20 @@
1
+
2
+ import InsigniaApiV1 from '../../../../src/api/v1/index.js';
3
+
4
+ const api = new InsigniaApiV1(process.env.INSIGNIA_EDUCATION_API_BASE_URL);
5
+
6
+ describe('api/v1/countries', () => {
7
+ test('get', async () => {
8
+ api.countries.get()
9
+ .then(response => {
10
+ response = Object.values(response);
11
+ expect(response.length > 0).toBe(true);
12
+ response.forEach(country => {
13
+ expect(country["id"]).toBeDefined();
14
+ expect(country["cod"]).toBeDefined();
15
+ expect(country["domain"]).toBeDefined();
16
+ expect(country["phone_prefix"]).toBeDefined();
17
+ })
18
+ });
19
+ });
20
+ });
@@ -0,0 +1,26 @@
1
+ import InsigniaApiV1 from '../../../../src/api/v1/index.js';
2
+
3
+ const api = new InsigniaApiV1(process.env.INSIGNIA_EDUCATION_API_BASE_URL);
4
+
5
+ const login = () => api.auth.login({
6
+ email: process.env.TEST_EMAIL,
7
+ password: process.env.TEST_PASSWORD,
8
+ });
9
+
10
+ describe('api/v1/coupons', () => {
11
+ test('get | authenticated', async () => {
12
+ await login();
13
+ await api.coupons.get()
14
+ .then(response => {
15
+ response = Object.values(response);
16
+ expect(Array.isArray(response)).toBe(true);
17
+ response.forEach(coupon => {
18
+ expect(coupon["id"]).toBeDefined();
19
+ expect(coupon["cod"]).toBeDefined();
20
+ expect(coupon["enabled"]).toBeDefined();
21
+ expect(coupon["created_at"]).toBeDefined();
22
+ expect(coupon["updated_at"]).toBeDefined();
23
+ });
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,19 @@
1
+ import {
2
+ api,
3
+ loginCustomer,
4
+ loginAdmin
5
+ } from '../../../../helpers.js';
6
+
7
+ describe('api/v1/courses/cod/:cod', () => {
8
+ test('get by cod | returns matching course', async () => {
9
+ const firstPage = await api.courses.get();
10
+ const cod = firstPage["data"][0]["cod"];
11
+ await api.courses.getByCod(cod)
12
+ .then(response => {
13
+ expect(response["id"]).toBeDefined();
14
+ expect(response["cod"]).toBe(cod);
15
+ expect(response["title"]).toBeDefined();
16
+ expect(response["enabled"]).toBeDefined();
17
+ });
18
+ });
19
+ });