@amityco/ts-sdk 6.1.0 → 6.1.1-4303148.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "6.1.0",
3
+ "version": "6.1.1-4303148.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -1,10 +1,10 @@
1
1
  import nock from 'nock';
2
2
 
3
- import { ASCApiError, ASCUnknownError } from '~/core/errors';
3
+ import { ASCApiError, ASCUnknownError, ASCError } from '~/core/errors';
4
4
  import { createFileFormData } from '~/utils/tests';
5
5
 
6
- import { getPastDate } from '~/core/model';
7
- import { createHttpTransport } from '../http';
6
+ import { getPastDate, getFutureDate } from '~/core/model';
7
+ import { createHttpTransport, RequestCancelation } from '../http';
8
8
 
9
9
  const baseUrl = 'https://non-exist.domain';
10
10
 
@@ -75,10 +75,48 @@ describe('core/transports', () => {
75
75
  nock(baseUrl).get('/api/v4/sessions').reply(200, expectedResolveValue);
76
76
 
77
77
  const instance = createHttpTransport(baseUrl);
78
- instance.defaults.metadata = { tokenExpiry: getPastDate() };
78
+ instance.defaults.metadata = {
79
+ tokenExpiry: getPastDate(),
80
+ isGlobalBanned: false,
81
+ isUserDeleted: false,
82
+ };
79
83
 
80
84
  const expected = expect.objectContaining({ data: expectedResolveValue });
81
85
  await expect(instance.get('/api/v4/sessions')).resolves.toEqual(expected);
82
86
  });
87
+
88
+ test('it should throw error is user is global banned', async () => {
89
+ const err = new ASCError(
90
+ RequestCancelation.UserGlobalBanned,
91
+ Amity.ServerError.GLOBAL_BAN,
92
+ Amity.ErrorLevel.FATAL,
93
+ );
94
+
95
+ const instance = createHttpTransport(baseUrl);
96
+ instance.defaults.metadata = {
97
+ tokenExpiry: getFutureDate(),
98
+ isGlobalBanned: true,
99
+ isUserDeleted: false,
100
+ };
101
+
102
+ await expect(instance.get('/foo')).rejects.toThrow(err);
103
+ });
104
+
105
+ test('it should throw error is user is deleted', async () => {
106
+ const err = new ASCError(
107
+ RequestCancelation.UserDeleted,
108
+ Amity.ServerError.UNAUTHORIZED,
109
+ Amity.ErrorLevel.FATAL,
110
+ );
111
+
112
+ const instance = createHttpTransport(baseUrl);
113
+ instance.defaults.metadata = {
114
+ tokenExpiry: getFutureDate(),
115
+ isGlobalBanned: false,
116
+ isUserDeleted: true,
117
+ };
118
+
119
+ await expect(instance.get('/foo')).rejects.toThrow(err);
120
+ });
83
121
  });
84
122
  });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=http.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.test.d.ts","sourceRoot":"","sources":["../../../../src/core/transports/test/http.test.ts"],"names":[],"mappings":""}
@@ -1,122 +0,0 @@
1
- import nock from 'nock';
2
-
3
- import { ASCApiError, ASCUnknownError, ASCError } from '~/core/errors';
4
- import { createFileFormData } from '~/utils/tests';
5
-
6
- import { getPastDate, getFutureDate } from '~/core/model';
7
- import { createHttpTransport, RequestCancelation } from '../http';
8
-
9
- const baseUrl = 'https://non-exist.domain';
10
-
11
- describe('core/transports', () => {
12
- describe('createHttpTransport', () => {
13
- beforeAll(nock.disableNetConnect);
14
- beforeEach(nock.cleanAll);
15
-
16
- test('should create axios instance with out error', () => {
17
- nock(baseUrl).get(/./).reply(200);
18
-
19
- expect(createHttpTransport(baseUrl)).not.toThrow();
20
- });
21
-
22
- test('instance should resolved http request', async () => {
23
- const expectedResolveValue = { foo: 'bar' };
24
- nock(baseUrl).get('/foo').reply(200, expectedResolveValue);
25
-
26
- const instance = createHttpTransport(baseUrl);
27
-
28
- const expected = expect.objectContaining({ data: expectedResolveValue });
29
- await expect(instance.get('/foo')).resolves.toEqual(expected);
30
- });
31
-
32
- test('instance should throw Error when got 400 response code', async () => {
33
- nock(baseUrl).get('/foo').reply(400);
34
-
35
- const instance = createHttpTransport(baseUrl);
36
-
37
- await expect(instance.get('/foo')).rejects.toThrow(Error);
38
- });
39
-
40
- test('instance should throw Error when got 500 response code', async () => {
41
- nock(baseUrl).get('/foo').reply(500);
42
-
43
- const instance = createHttpTransport(baseUrl);
44
-
45
- await expect(instance.get('/foo')).rejects.toThrow(Error);
46
- });
47
-
48
- test('instance should throw `ASCUnknownError` when got `fail` status in payload', async () => {
49
- nock(baseUrl).get('/foo').reply(500, { status: 'fail', message: 'something fail' });
50
-
51
- const instance = createHttpTransport(baseUrl);
52
-
53
- await expect(instance.get('/foo')).rejects.toThrow(ASCUnknownError);
54
- });
55
-
56
- test('instance should throw `ASCApiError` when got `error` status in payload', async () => {
57
- nock(baseUrl).get('/foo').reply(500, { status: 'error', message: 'something error' });
58
-
59
- const instance = createHttpTransport(baseUrl);
60
-
61
- await expect(instance.get('/foo')).rejects.toThrow(ASCApiError);
62
- });
63
-
64
- test('instance should receive formData', async () => {
65
- const formData = createFileFormData();
66
- nock(baseUrl).post('/foo').reply(200);
67
-
68
- const instance = createHttpTransport(baseUrl);
69
-
70
- await expect(instance.post('/foo', formData)).resolves.not.toThrow();
71
- });
72
-
73
- test('should not check token expiration for token creation url', async () => {
74
- const expectedResolveValue = { foo: 'bar' };
75
- nock(baseUrl).get('/api/v4/sessions').reply(200, expectedResolveValue);
76
-
77
- const instance = createHttpTransport(baseUrl);
78
- instance.defaults.metadata = {
79
- tokenExpiry: getPastDate(),
80
- isGlobalBanned: false,
81
- isUserDeleted: false,
82
- };
83
-
84
- const expected = expect.objectContaining({ data: expectedResolveValue });
85
- await expect(instance.get('/api/v4/sessions')).resolves.toEqual(expected);
86
- });
87
-
88
- test('it should throw error is user is global banned', async () => {
89
- const err = new ASCError(
90
- RequestCancelation.UserGlobalBanned,
91
- Amity.ServerError.GLOBAL_BAN,
92
- Amity.ErrorLevel.FATAL,
93
- );
94
-
95
- const instance = createHttpTransport(baseUrl);
96
- instance.defaults.metadata = {
97
- tokenExpiry: getFutureDate(),
98
- isGlobalBanned: true,
99
- isUserDeleted: false,
100
- };
101
-
102
- await expect(instance.get('/foo')).rejects.toThrow(ASCError);
103
- });
104
-
105
- test('it should throw error is user is deleted', async () => {
106
- const err = new ASCError(
107
- RequestCancelation.UserDeleted,
108
- Amity.ServerError.UNAUTHORIZED,
109
- Amity.ErrorLevel.FATAL,
110
- );
111
-
112
- const instance = createHttpTransport(baseUrl);
113
- instance.defaults.metadata = {
114
- tokenExpiry: getFutureDate(),
115
- isGlobalBanned: false,
116
- isUserDeleted: true,
117
- };
118
-
119
- await expect(instance.get('/foo')).rejects.toThrow(ASCError);
120
- });
121
- });
122
- });