@insignia-education/api-sdk-js 0.9.12 → 0.9.17

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 (58) hide show
  1. package/.github/hooks/pre-commit +10 -1
  2. package/.github/workflows/npm-publish-github-packages.yml +6 -5
  3. package/eslint.config.mjs +19 -0
  4. package/index.js +2 -3
  5. package/jest.config.mjs +22 -197
  6. package/package.json +5 -2
  7. package/src/Client.js +17 -23
  8. package/src/api/index.js +6 -17
  9. package/src/api/v1/index.js +35 -42
  10. package/src/index.js +4 -17
  11. package/tests/client.test.js +6 -45
  12. package/tests/integration/api.v1..test.js +76 -0
  13. package/tests/integration/auth.test.js +40 -0
  14. package/tests/integration/cookieJar.js +48 -0
  15. package/tests/integration/loadEnv.js +16 -0
  16. package/Cart.js +0 -40
  17. package/coverage/clover.xml +0 -703
  18. package/coverage/coverage-final.json +0 -30
  19. package/coverage/lcov-report/base.css +0 -224
  20. package/coverage/lcov-report/block-navigation.js +0 -87
  21. package/coverage/lcov-report/favicon.png +0 -0
  22. package/coverage/lcov-report/index.html +0 -131
  23. package/coverage/lcov-report/prettify.css +0 -1
  24. package/coverage/lcov-report/prettify.js +0 -2
  25. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  26. package/coverage/lcov-report/sorter.js +0 -210
  27. package/coverage/lcov-report/src/Client.js.html +0 -202
  28. package/coverage/lcov-report/src/api/v1/Accounts.js.html +0 -151
  29. package/coverage/lcov-report/src/api/v1/Auth.js.html +0 -130
  30. package/coverage/lcov-report/src/api/v1/Categories.js.html +0 -121
  31. package/coverage/lcov-report/src/api/v1/Changelogs.js.html +0 -118
  32. package/coverage/lcov-report/src/api/v1/Configs.js.html +0 -121
  33. package/coverage/lcov-report/src/api/v1/ContactForms.js.html +0 -121
  34. package/coverage/lcov-report/src/api/v1/ConversationalTopics.js.html +0 -121
  35. package/coverage/lcov-report/src/api/v1/Countries.js.html +0 -112
  36. package/coverage/lcov-report/src/api/v1/Coupons.js.html +0 -121
  37. package/coverage/lcov-report/src/api/v1/Courses.js.html +0 -328
  38. package/coverage/lcov-report/src/api/v1/Currencies.js.html +0 -115
  39. package/coverage/lcov-report/src/api/v1/Files.js.html +0 -115
  40. package/coverage/lcov-report/src/api/v1/Forums.js.html +0 -157
  41. package/coverage/lcov-report/src/api/v1/Hashes.js.html +0 -118
  42. package/coverage/lcov-report/src/api/v1/Insignias.js.html +0 -121
  43. package/coverage/lcov-report/src/api/v1/Languages.js.html +0 -121
  44. package/coverage/lcov-report/src/api/v1/MailBlacklist.js.html +0 -118
  45. package/coverage/lcov-report/src/api/v1/Organizations.js.html +0 -118
  46. package/coverage/lcov-report/src/api/v1/Quizzes.js.html +0 -181
  47. package/coverage/lcov-report/src/api/v1/ShortLinks.js.html +0 -121
  48. package/coverage/lcov-report/src/api/v1/Surveys.js.html +0 -181
  49. package/coverage/lcov-report/src/api/v1/Tags.js.html +0 -121
  50. package/coverage/lcov-report/src/api/v1/Taxes.js.html +0 -121
  51. package/coverage/lcov-report/src/api/v1/Teacher.js.html +0 -196
  52. package/coverage/lcov-report/src/api/v1/Translations.js.html +0 -121
  53. package/coverage/lcov-report/src/api/v1/UserTypes.js.html +0 -121
  54. package/coverage/lcov-report/src/api/v1/Users.js.html +0 -331
  55. package/coverage/lcov-report/src/api/v1/Zoom.js.html +0 -154
  56. package/coverage/lcov-report/src/api/v1/index.html +0 -521
  57. package/coverage/lcov-report/src/index.html +0 -116
  58. package/coverage/lcov.info +0 -1822
@@ -1,13 +1,22 @@
1
1
  #!/bin/bash
2
+ set -e
2
3
 
3
4
  PACKAGE=$(node -p "require('./package.json').name")
4
5
  VERSION=$(node -p "require('./package.json').version")
5
6
 
7
+ echo "Running lint..."
8
+ npm run lint
9
+
10
+ echo "Running tests..."
11
+ npm test
12
+
13
+ echo "Checking if ${PACKAGE}@${VERSION} is already published..."
6
14
  STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://registry.npmjs.org/${PACKAGE}/${VERSION}")
15
+ echo $STATUS
7
16
  if [ "$STATUS" = "200" ]; then
8
17
  echo "Error: ${PACKAGE}@${VERSION} is already published on NPM."
9
18
  echo "Bump the version in package.json before committing."
10
- exit 1
19
+ exit 1
11
20
  fi
12
21
 
13
22
  exit 0
@@ -18,11 +18,12 @@ jobs:
18
18
  node-version: 25
19
19
  registry-url: 'https://registry.npmjs.org/'
20
20
 
21
- - name: Install dependencies
22
- run: npm install
23
-
24
- - name: Run tests
25
- run: npm test
21
+ # - name: Install dependencies
22
+ # run: npm install
23
+
24
+ # we remove tests until we have a beta env for the api
25
+ # - name: Run tests
26
+ # run: npm test
26
27
 
27
28
  - name: Publish to NPM
28
29
  run: npm publish --access public
@@ -0,0 +1,19 @@
1
+ import js from "@eslint/js";
2
+ import globals from "globals";
3
+
4
+ export default [
5
+ js.configs.recommended,
6
+ {
7
+ files: ["src/**/*.js"],
8
+ languageOptions: {
9
+ globals: {
10
+ ...globals.node,
11
+ fetch: "readonly",
12
+ },
13
+ },
14
+ rules: {
15
+ "no-unused-vars": "warn",
16
+ "no-console": "warn",
17
+ },
18
+ },
19
+ ];
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import InsigniaApiV1 from './src/v1/index.js';
1
+ import Insignia from './src/index.js';
2
2
 
3
- export default InsigniaApiV1;
4
- export { InsigniaApiV1 };
3
+ export default Insignia;
package/jest.config.mjs CHANGED
@@ -1,201 +1,26 @@
1
- /**
2
- * For a detailed explanation regarding each configuration property, visit:
3
- * https://jestjs.io/docs/configuration
4
- */
5
-
6
1
  /** @type {import('jest').Config} */
7
2
  const config = {
8
- // All imported modules in your tests should be mocked automatically
9
- // automock: false,
10
-
11
- // Stop running tests after `n` failures
12
- // bail: 0,
13
-
14
- // The directory where Jest should store its cached dependency information
15
- // cacheDirectory: "/private/var/folders/dr/s_4jjf_x5wv7vc0bgx5j8pw80000gn/T/jest_dx",
16
-
17
- // Automatically clear mock calls, instances, contexts and results before every test
18
- // clearMocks: false,
19
-
20
- // Indicates whether the coverage information should be collected while executing the test
21
- collectCoverage: true,
22
-
23
- // An array of glob patterns indicating a set of files for which coverage information should be collected
24
- // collectCoverageFrom: undefined,
25
-
26
- // The directory where Jest should output its coverage files
27
- coverageDirectory: "coverage",
28
-
29
- // An array of regexp pattern strings used to skip coverage collection
30
- // coveragePathIgnorePatterns: [
31
- // "/node_modules/"
32
- // ],
33
-
34
- // Indicates which provider should be used to instrument code for coverage
35
- coverageProvider: "v8",
36
-
37
- // A list of reporter names that Jest uses when writing coverage reports
38
- // coverageReporters: [
39
- // "json",
40
- // "text",
41
- // "lcov",
42
- // "clover"
43
- // ],
44
-
45
- // An object that configures minimum threshold enforcement for coverage results
46
- // coverageThreshold: undefined,
47
-
48
- // A path to a custom dependency extractor
49
- // dependencyExtractor: undefined,
50
-
51
- // Make calling deprecated APIs throw helpful error messages
52
- // errorOnDeprecated: false,
53
-
54
- // The default configuration for fake timers
55
- // fakeTimers: {
56
- // "enableGlobally": false
57
- // },
58
-
59
- // Force coverage collection from ignored files using an array of glob patterns
60
- // forceCoverageMatch: [],
61
-
62
- // A path to a module which exports an async function that is triggered once before all test suites
63
- // globalSetup: undefined,
64
-
65
- // A path to a module which exports an async function that is triggered once after all test suites
66
- // globalTeardown: undefined,
67
-
68
- // A set of global variables that need to be available in all test environments
69
- // globals: {},
70
-
71
- // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
72
- // maxWorkers: "50%",
73
-
74
- // An array of directory names to be searched recursively up from the requiring module's location
75
- // moduleDirectories: [
76
- // "node_modules"
77
- // ],
78
-
79
- // An array of file extensions your modules use
80
- // moduleFileExtensions: [
81
- // "js",
82
- // "mjs",
83
- // "cjs",
84
- // "jsx",
85
- // "ts",
86
- // "tsx",
87
- // "json",
88
- // "node"
89
- // ],
90
-
91
- // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
92
- // moduleNameMapper: {},
93
-
94
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
95
- // modulePathIgnorePatterns: [],
96
-
97
- // Activates notifications for test results
98
- // notify: false,
99
-
100
- // An enum that specifies notification mode. Requires { notify: true }
101
- // notifyMode: "failure-change",
102
-
103
- // A preset that is used as a base for Jest's configuration
104
- // preset: undefined,
105
-
106
- // Run tests from one or more projects
107
- // projects: undefined,
108
-
109
- // Use this configuration option to add custom reporters to Jest
110
- // reporters: undefined,
111
-
112
- // Automatically reset mock state before every test
113
- // resetMocks: false,
114
-
115
- // Reset the module registry before running each individual test
116
- // resetModules: false,
117
-
118
- // A path to a custom resolver
119
- // resolver: undefined,
120
-
121
- // Automatically restore mock state and implementation before every test
122
- // restoreMocks: false,
123
-
124
- // The root directory that Jest should scan for tests and modules within
125
- // rootDir: undefined,
126
-
127
- // A list of paths to directories that Jest should use to search for files in
128
- // roots: [
129
- // "<rootDir>"
130
- // ],
131
-
132
- // Allows you to use a custom runner instead of Jest's default test runner
133
- // runner: "jest-runner",
134
-
135
- // The paths to modules that run some code to configure or set up the testing environment before each test
136
- // setupFiles: [],
137
-
138
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
139
- // setupFilesAfterEnv: [],
140
-
141
- // The number of seconds after which a test is considered as slow and reported as such in the results.
142
- // slowTestThreshold: 5,
143
-
144
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
145
- // snapshotSerializers: [],
146
-
147
- // The test environment that will be used for testing
148
- // testEnvironment: "jest-environment-node",
149
-
150
- // Options that will be passed to the testEnvironment
151
- // testEnvironmentOptions: {},
152
-
153
- // Adds a location field to test results
154
- // testLocationInResults: false,
155
-
156
- // The glob patterns Jest uses to detect test files
157
- // testMatch: [
158
- // "**/__tests__/**/*.[jt]s?(x)",
159
- // "**/?(*.)+(spec|test).[tj]s?(x)"
160
- // ],
161
-
162
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
163
- // testPathIgnorePatterns: [
164
- // "/node_modules/"
165
- // ],
166
-
167
- // The regexp pattern or array of patterns that Jest uses to detect test files
168
- // testRegex: [],
169
-
170
- // This option allows the use of a custom results processor
171
- // testResultsProcessor: undefined,
172
-
173
- // This option allows use of a custom test runner
174
- // testRunner: "jest-circus/runner",
175
-
176
- // A map from regular expressions to paths to transformers
177
- // transform: undefined,
178
-
179
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
180
- // transformIgnorePatterns: [
181
- // "/node_modules/",
182
- // "\\.pnp\\.[^\\/]+$"
183
- // ],
184
-
185
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
186
- // unmockedModulePathPatterns: undefined,
187
-
188
- // Indicates whether each individual test should be reported during the run
189
- // verbose: undefined,
190
-
191
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
192
- // watchPathIgnorePatterns: [],
193
-
194
- // Whether to use watchman for file crawling
195
- // watchman: true,
196
-
197
- transform: {
198
- '^.+\\.(js|jsx)$': 'babel-jest',
199
- }
3
+ collectCoverage: true,
4
+ coverageDirectory: 'coverage',
5
+ coverageProvider: 'v8',
6
+
7
+ projects: [
8
+ {
9
+ displayName: 'unit',
10
+ testMatch: [
11
+ '<rootDir>/tests/client.test.js',
12
+ '<rootDir>/tests/api/**/*.test.js',
13
+ ],
14
+ transform: { '^.+\\.(js|jsx)$': 'babel-jest' },
15
+ },
16
+ {
17
+ displayName: 'integration',
18
+ testMatch: ['<rootDir>/tests/integration/**/*.test.js'],
19
+ transform: { '^.+\\.(js|jsx)$': 'babel-jest' },
20
+ setupFiles: ['<rootDir>/tests/integration/loadEnv.js'],
21
+ testTimeout: 30000,
22
+ },
23
+ ],
200
24
  };
25
+
201
26
  export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insignia-education/api-sdk-js",
3
- "version": "0.9.12",
3
+ "version": "0.9.17",
4
4
  "description": "JavaScript SDK for the Insignia Education API",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -10,7 +10,8 @@
10
10
  "./api/v1": "./src/api/v1/index.js"
11
11
  },
12
12
  "scripts": {
13
- "test": "jest"
13
+ "test": "jest",
14
+ "lint": "eslint src/"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
@@ -30,6 +31,8 @@
30
31
  "devDependencies": {
31
32
  "@babel/preset-env": "^7.26.0",
32
33
  "babel-jest": "^30.3.0",
34
+ "@eslint/js": "^9.0.0",
35
+ "eslint": "^9.0.0",
33
36
  "jest": "^30.3.0",
34
37
  "jest-html-reporter": "^4.3.0"
35
38
  }
package/src/Client.js CHANGED
@@ -1,39 +1,33 @@
1
1
  export default class InsigniaClient {
2
2
  #baseUrl;
3
- #token;
4
3
 
5
- constructor(baseUrl = null, token = null) {
6
- const resolved = baseUrl
7
- ?? process.env.INSIGNIA_EDUCATION_API_BASE_URL
8
- ?? 'https://insigniaeducation.com';
9
- this.#baseUrl = resolved.replace(/\/$/, '');
10
- this.#token = token;
4
+ constructor(baseUrl) {
5
+ this.#baseUrl = InsigniaClient._resolve(baseUrl);
11
6
  }
12
7
 
13
- setToken(token) {
14
- this.#token = token;
15
- }
16
-
17
- getToken() {
18
- return this.#token;
8
+ static _resolve(baseUrl) {
9
+ baseUrl = baseUrl
10
+ ?? process.env.INSIGNIA_EDUCATION_API_BASE_URL
11
+ ?? 'https://insigniaeducation.com';
12
+ baseUrl = baseUrl.replace(/\/$/, '')
13
+ return baseUrl;
19
14
  }
20
15
 
21
16
  #headers() {
22
- const headers = { 'Content-Type': 'application/json' };
23
- if (this.#token) headers['Authorization'] = `Bearer ${this.#token}`;
24
- return headers;
17
+ return { 'Content-Type': 'application/json' };
25
18
  }
26
19
 
27
20
  async #request(method, path, body = null) {
28
- const options = { method, headers: this.#headers() };
21
+ const options = { method, headers: this.#headers(), credentials: 'include' };
29
22
  if (body !== null) options.body = JSON.stringify(body);
30
23
  const response = await fetch(`${this.#baseUrl}${path}`, options);
31
- return response.json();
24
+ const data = await response.json();
25
+ return data?.success ? data.response : data;
32
26
  }
33
27
 
34
- get(path) { return this.#request('GET', path); }
35
- post(path, body = null){ return this.#request('POST', path, body); }
36
- put(path, body = null) { return this.#request('PUT', path, body); }
37
- patch(path, body = null){ return this.#request('PATCH', path, body); }
38
- del(path) { return this.#request('DELETE', path); }
28
+ get(path) { return this.#request('GET', path); }
29
+ post(path, body = null) { return this.#request('POST', path, body); }
30
+ put(path, body = null) { return this.#request('PUT', path, body); }
31
+ patch(path, body = null){ return this.#request('PATCH', path, body); }
32
+ del(path) { return this.#request('DELETE', path); }
39
33
  }
package/src/api/index.js CHANGED
@@ -1,20 +1,9 @@
1
- import InsigniaClient from "../Client";
2
- import InsigniaApiV1 from "./v1";
1
+ import Insignia from '../index.js';
3
2
 
4
-
5
- export default class InsigniaApi {
6
- #client;
7
-
8
- constructor(baseUrl = null, token = null) {
9
- this.#client = new InsigniaClient(baseUrl, token);
10
- this.v1 = new InsigniaApiV1(baseUrl, token);
11
- }
12
-
13
- setToken(token) {
14
- this.#client.setToken(token);
15
- }
16
-
17
- getToken() {
18
- return this.#client.getToken();
3
+ export default class InsigniaApi extends Insignia {
4
+ constructor(baseUrl = null) {
5
+ let url = InsigniaApi._resolve(baseUrl);
6
+ if (!/\/api(\/|$)/.test(url)) url += '/api';
7
+ super(url);
19
8
  }
20
9
  }
@@ -1,4 +1,4 @@
1
- import InsigniaClient from '../../Client.js';
1
+ import InsigniaApi from '../index.js';
2
2
  import Auth from './Auth.js';
3
3
  import Accounts from './Accounts.js';
4
4
  import Categories from './Categories.js';
@@ -28,47 +28,40 @@ import UserTypes from './UserTypes.js';
28
28
  import Users from './Users.js';
29
29
  import Zoom from './Zoom.js';
30
30
 
31
- export default class InsigniaApiV1 {
32
- #client;
31
+ export default class InsigniaApiV1 extends InsigniaApi {
32
+ constructor(baseUrl = null) {
33
+ let url = InsigniaApiV1._resolve(baseUrl);
34
+ if (!/\/api(\/|$)/.test(url)) url += '/api';
35
+ if (!/\/v1(\/|$)/.test(url)) url += '/v1';
36
+ super(url);
33
37
 
34
- constructor(baseUrl = null, token = null) {
35
- this.#client = new InsigniaClient(baseUrl, token);
36
-
37
- this.auth = new Auth(this.#client);
38
- this.accounts = new Accounts(this.#client);
39
- this.categories = new Categories(this.#client);
40
- this.changelogs = new Changelogs(this.#client);
41
- this.configs = new Configs(this.#client);
42
- this.contactForms = new ContactForms(this.#client);
43
- this.conversationalTopics = new ConversationalTopics(this.#client);
44
- this.countries = new Countries(this.#client);
45
- this.coupons = new Coupons(this.#client);
46
- this.courses = new Courses(this.#client);
47
- this.currencies = new Currencies(this.#client);
48
- this.files = new Files(this.#client);
49
- this.forums = new Forums(this.#client);
50
- this.hashes = new Hashes(this.#client);
51
- this.insignias = new Insignias(this.#client);
52
- this.languages = new Languages(this.#client);
53
- this.mailBlacklist = new MailBlacklist(this.#client);
54
- this.organizations = new Organizations(this.#client);
55
- this.quizzes = new Quizzes(this.#client);
56
- this.shortLinks = new ShortLinks(this.#client);
57
- this.surveys = new Surveys(this.#client);
58
- this.tags = new Tags(this.#client);
59
- this.taxes = new Taxes(this.#client);
60
- this.teacher = new Teacher(this.#client);
61
- this.translations = new Translations(this.#client);
62
- this.userTypes = new UserTypes(this.#client);
63
- this.users = new Users(this.#client);
64
- this.zoom = new Zoom(this.#client);
65
- }
66
-
67
- setToken(token) {
68
- this.#client.setToken(token);
69
- }
70
-
71
- getToken() {
72
- return this.#client.getToken();
38
+ this.auth = new Auth(this);
39
+ this.accounts = new Accounts(this);
40
+ this.categories = new Categories(this);
41
+ this.changelogs = new Changelogs(this);
42
+ this.configs = new Configs(this);
43
+ this.contactForms = new ContactForms(this);
44
+ this.conversationalTopics = new ConversationalTopics(this);
45
+ this.countries = new Countries(this);
46
+ this.coupons = new Coupons(this);
47
+ this.courses = new Courses(this);
48
+ this.currencies = new Currencies(this);
49
+ this.files = new Files(this);
50
+ this.forums = new Forums(this);
51
+ this.hashes = new Hashes(this);
52
+ this.insignias = new Insignias(this);
53
+ this.languages = new Languages(this);
54
+ this.mailBlacklist = new MailBlacklist(this);
55
+ this.organizations = new Organizations(this);
56
+ this.quizzes = new Quizzes(this);
57
+ this.shortLinks = new ShortLinks(this);
58
+ this.surveys = new Surveys(this);
59
+ this.tags = new Tags(this);
60
+ this.taxes = new Taxes(this);
61
+ this.teacher = new Teacher(this);
62
+ this.translations = new Translations(this);
63
+ this.userTypes = new UserTypes(this);
64
+ this.users = new Users(this);
65
+ this.zoom = new Zoom(this);
73
66
  }
74
67
  }
package/src/index.js CHANGED
@@ -1,21 +1,8 @@
1
- import InsigniaClient from "./Client";
2
- import InsigniaApi from "./api";
1
+ import InsigniaClient from './Client.js';
3
2
 
4
-
5
- export default class Insignia {
6
- #client;
3
+ export default class Insignia extends InsigniaClient {
7
4
 
8
- constructor(baseUrl = null, token = null) {
9
- this.#client = new InsigniaClient(baseUrl, token);
10
- this.api = new InsigniaApi(baseUrl, token);
11
- }
12
-
13
- setToken(token) {
14
- this.#client.setToken(token);
15
- }
16
-
17
- getToken() {
18
- return this.#client.getToken();
5
+ constructor(baseUrl = null) {
6
+ super(Insignia._resolve(baseUrl));
19
7
  }
20
8
  }
21
-
@@ -81,51 +81,6 @@ describe('baseUrl resolution', () => {
81
81
  });
82
82
  });
83
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
84
  // ─── HTTP methods ─────────────────────────────────────────────────────────────
130
85
 
131
86
  describe('HTTP methods', () => {
@@ -203,6 +158,12 @@ describe('HTTP methods', () => {
203
158
  expect(options.headers['Content-Type']).toBe('application/json');
204
159
  });
205
160
 
161
+ test('credentials is always include', async () => {
162
+ await client.get('/path');
163
+ const [, options] = global.fetch.mock.calls[0];
164
+ expect(options.credentials).toBe('include');
165
+ });
166
+
206
167
  test('returns parsed JSON from response', async () => {
207
168
  global.fetch = jest.fn().mockResolvedValue({
208
169
  json: () => Promise.resolve({ id: 1, name: 'test' }),
@@ -0,0 +1,76 @@
1
+ import './cookieJar.js';
2
+ import InsigniaApiV1 from '../../src/api/v1/index.js';
3
+
4
+ const api = new InsigniaApiV1(process.env.INSIGNIA_EDUCATION_API_BASE_URL);
5
+ beforeAll(async () => {
6
+ const email = process.env.TEST_EMAIL;
7
+ const password = process.env.TEST_PASSWORD;
8
+ const login = await api.auth.login({ email, password });
9
+ });
10
+
11
+ afterAll(async () => {
12
+ await api.auth.logout();
13
+ });
14
+
15
+ // ─── Read-only endpoints ──────────────────────────────────────────────────────
16
+ describe('Countries', () => {
17
+ test('get() returns a list', async () => {
18
+ api.countries.get()
19
+ .then(response => {
20
+ expect(response["11"]).toBeDefined();
21
+ expect(response["11"]["id"]).toBeDefined();
22
+ expect(response["11"]["cod"]).toBeDefined();
23
+ expect(response["11"]["domain"]).toBeDefined();
24
+ expect(response["11"]["phone_prefix"]).toBeDefined();
25
+ });
26
+ });
27
+ });
28
+
29
+ describe('Currencies', () => {
30
+ test('get() returns a list', async () => {
31
+ api.currencies.get()
32
+ .then(response => {
33
+ expect(response["1"]).toBeDefined();
34
+ expect(response["1"]["id"]).toBeDefined();
35
+ expect(response["1"]["country_id"]).toBeDefined();
36
+ expect(response["1"]["cod"]).toBeDefined();
37
+ expect(response["1"]["title"]).toBeDefined();
38
+ expect(response["1"]["enabled"]).toBeDefined();
39
+ expect(response["1"]["has_double_expression"]).toBeDefined();
40
+ expect(response["1"]["double_expression_by"]).toBeDefined();
41
+ expect(response["1"]["created_at"]).toBeDefined();
42
+ expect(response["1"]["updated_at"]).toBeDefined();
43
+ expect(response["1"]["deleted_at"]).toBeDefined();
44
+ });
45
+ });
46
+
47
+ test('getValues() returns exchange values', async () => {
48
+ const res = await api.currencies.getValues()
49
+ .then(response => {
50
+ expect(response["USD"]).toBeDefined();
51
+ expect(response["USD"]["id"]).toBeDefined();
52
+ expect(response["USD"]["currency_id"]).toBeDefined();
53
+ expect(response["USD"]["value"]).toBeDefined();
54
+ expect(response["USD"]["created_at"]).toBeDefined();
55
+ expect(response["USD"]["updated_at"]).toBeDefined();
56
+ });
57
+ });
58
+ });
59
+
60
+ describe('Languages', () => {
61
+ test('get() returns a list', async () => {
62
+ const res = await api.languages.get()
63
+ .then(response => {
64
+ expect(response["1"]).toBeDefined();
65
+ expect(response["1"]["id"]).toBeDefined();
66
+ expect(response["1"]["iso"]).toBeDefined();
67
+ expect(response["1"]["flag_emoji"]).toBeDefined();
68
+ expect(response["1"]["enabled"]).toBeDefined();
69
+ expect(response["1"]["default"]).toBeDefined();
70
+ expect(response["1"]["created_at"]).toBeDefined();
71
+ expect(response["1"]["updated_at"]).toBeDefined();
72
+ expect(response["1"]["deleted_at"]).toBeDefined();
73
+ });
74
+ });
75
+ });
76
+