@amityco/ts-sdk 0.0.1-beta-34 → 0.0.1-beta-35

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 (51) hide show
  1. package/dist/cache/utils/tests/encodeKey.test.d.ts +2 -0
  2. package/dist/cache/utils/tests/encodeKey.test.d.ts.map +1 -0
  3. package/dist/cache/utils/tests/partialMatch.test.d.ts +2 -0
  4. package/dist/cache/utils/tests/partialMatch.test.d.ts.map +1 -0
  5. package/dist/client/api/tests/activeClient.test.d.ts +2 -0
  6. package/dist/client/api/tests/activeClient.test.d.ts.map +1 -0
  7. package/dist/client/api/tests/activeUser.test.d.ts +2 -0
  8. package/dist/client/api/tests/activeUser.test.d.ts.map +1 -0
  9. package/dist/index.cjs.js +9 -0
  10. package/dist/index.esm.js +9 -0
  11. package/dist/index.umd.js +1 -1
  12. package/dist/post/events/tests/onPostApproved.test.d.ts +2 -0
  13. package/dist/post/events/tests/onPostApproved.test.d.ts.map +1 -0
  14. package/dist/post/events/tests/onPostCreated.test.d.ts +2 -0
  15. package/dist/post/events/tests/onPostCreated.test.d.ts.map +1 -0
  16. package/dist/post/events/tests/onPostDeclined.test.d.ts +2 -0
  17. package/dist/post/events/tests/onPostDeclined.test.d.ts.map +1 -0
  18. package/dist/post/events/tests/onPostDeleted.test.d.ts +2 -0
  19. package/dist/post/events/tests/onPostDeleted.test.d.ts.map +1 -0
  20. package/dist/post/events/tests/onPostFlagged.test.d.ts +2 -0
  21. package/dist/post/events/tests/onPostFlagged.test.d.ts.map +1 -0
  22. package/dist/post/events/tests/onPostReactionAdded.test.d.ts +2 -0
  23. package/dist/post/events/tests/onPostReactionAdded.test.d.ts.map +1 -0
  24. package/dist/post/events/tests/onPostReactionRemoved.test.d.ts +2 -0
  25. package/dist/post/events/tests/onPostReactionRemoved.test.d.ts.map +1 -0
  26. package/dist/post/events/tests/onPostUnflagged.test.d.ts +2 -0
  27. package/dist/post/events/tests/onPostUnflagged.test.d.ts.map +1 -0
  28. package/dist/post/events/tests/onPostUpdated.test.d.ts +2 -0
  29. package/dist/post/events/tests/onPostUpdated.test.d.ts.map +1 -0
  30. package/dist/post/observers/livePosts.d.ts.map +1 -1
  31. package/dist/post/observers/tests/livePosts.test.d.ts +2 -0
  32. package/dist/post/observers/tests/livePosts.test.d.ts.map +1 -0
  33. package/dist/utils/tests/dummy/post.d.ts +15 -0
  34. package/dist/utils/tests/dummy/post.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/cache/utils/tests/encodeKey.test.ts +19 -0
  37. package/src/cache/utils/tests/partialMatch.test.ts +13 -0
  38. package/src/client/api/tests/activeClient.test.ts +20 -0
  39. package/src/client/api/tests/activeUser.test.ts +20 -0
  40. package/src/post/events/tests/onPostApproved.test.ts +33 -0
  41. package/src/post/events/tests/onPostCreated.test.ts +33 -0
  42. package/src/post/events/tests/onPostDeclined.test.ts +33 -0
  43. package/src/post/events/tests/onPostDeleted.test.ts +33 -0
  44. package/src/post/events/tests/onPostFlagged.test.ts +33 -0
  45. package/src/post/events/tests/onPostReactionAdded.test.ts +40 -0
  46. package/src/post/events/tests/onPostReactionRemoved.test.ts +40 -0
  47. package/src/post/events/tests/onPostUnflagged.test.ts +33 -0
  48. package/src/post/events/tests/onPostUpdated.test.ts +33 -0
  49. package/src/post/observers/livePosts.ts +10 -0
  50. package/src/post/observers/tests/livePosts.test.ts +273 -0
  51. package/src/utils/tests/dummy/post.ts +34 -0
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostApproved.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostApproved.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostApproved.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostCreated.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostCreated.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostCreated.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostDeclined.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostDeclined.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostDeclined.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostDeleted.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostDeleted.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostDeleted.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostFlagged.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostFlagged.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostFlagged.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostReactionAdded.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostReactionAdded.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostReactionAdded.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostReactionRemoved.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostReactionRemoved.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostReactionRemoved.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostUnflagged.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostUnflagged.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostUnflagged.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=onPostUpdated.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onPostUpdated.test.d.ts","sourceRoot":"","sources":["../../../../src/post/events/tests/onPostUpdated.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"livePosts.d.ts","sourceRoot":"","sources":["../../../src/post/observers/livePosts.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS,WACZ,MAAM,kBAAkB,YACtB,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,KAClC,MAAM,YAkHR,CAAC"}
1
+ {"version":3,"file":"livePosts.d.ts","sourceRoot":"","sources":["../../../src/post/observers/livePosts.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS,WACZ,MAAM,kBAAkB,YACtB,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,KAClC,MAAM,YA4HR,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=livePosts.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"livePosts.test.d.ts","sourceRoot":"","sources":["../../../../src/post/observers/tests/livePosts.test.ts"],"names":[],"mappings":""}
@@ -2,6 +2,9 @@ export declare const post11: Amity.Post;
2
2
  export declare const comment11: Amity.Comment;
3
3
  export declare const post12: Amity.Post;
4
4
  export declare const post13: Amity.Post;
5
+ export declare const post14: Amity.Post;
6
+ export declare const post15: Amity.Post;
7
+ export declare const post16: Amity.Post;
5
8
  export declare const posts: {
6
9
  targetId: string;
7
10
  targetType: Amity.PostTargetType;
@@ -12,6 +15,18 @@ export declare const posts: {
12
15
  export declare const commentPayload: Amity.CommentPayload;
13
16
  export declare const postPayload: Amity.PostPayload;
14
17
  export declare const postQueryResponse: {
18
+ data: {
19
+ posts: Amity.Post<any>[];
20
+ files: never[];
21
+ reactor: {
22
+ userId: string;
23
+ };
24
+ paging: {
25
+ next: string;
26
+ };
27
+ };
28
+ };
29
+ export declare const postQueryResponsePage2: {
15
30
  data: {
16
31
  posts: Amity.Post<any>[];
17
32
  files: never[];
@@ -1 +1 @@
1
- {"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/post.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAoB1B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,OAuB7B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAG1B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAG1B,CAAC;AAEF,eAAO,MAAM,KAAK;;;;;;CAMjB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,cAGlC,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,WAM/B,CAAC;AAIF,eAAO,MAAM,iBAAiB;;;;;;;;CAQ7B,CAAC"}
1
+ {"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/post.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAoB1B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,OAuB7B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAG1B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAG1B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAM1B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAO1B,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,IAI1B,CAAC;AAEF,eAAO,MAAM,KAAK;;;;;;CAMjB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,cAGlC,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,WAM/B,CAAC;AAIF,eAAO,MAAM,iBAAiB;;;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;CAQlC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "0.0.1-beta-34",
3
+ "version": "0.0.1-beta-35",
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",
@@ -0,0 +1,19 @@
1
+ import { encodeKey } from '..';
2
+
3
+ describe('cache util > encodeKey', () => {
4
+ test('it should return encoded string', () => {
5
+ const key = ['post', 'get', 'post-id'];
6
+ const keyObject = { 0: 'post', 1: 'get', 2: 'post-id' };
7
+
8
+ const expected = JSON.stringify(keyObject);
9
+
10
+ expect(encodeKey(key)).toBe(expected);
11
+ });
12
+
13
+ test('it should normalize key', () => {
14
+ const key = [{ c: 'last', b: 'middle', a: 'first' }];
15
+ const expected = JSON.stringify({ 0: { a: 'first', b: 'middle', c: 'last' } });
16
+
17
+ expect(encodeKey(key)).toBe(expected);
18
+ });
19
+ });
@@ -0,0 +1,13 @@
1
+ import { partialMatch } from '..';
2
+
3
+ import { post11, post12 } from '~/utils/tests';
4
+
5
+ describe('cache util > partialMatch', () => {
6
+ test('it should return true if objects are deep equal', () => {
7
+ expect(partialMatch(post11, post11)).toBe(true);
8
+ });
9
+
10
+ test('it should return false if objects are not deep equal', () => {
11
+ expect(partialMatch(post11, post12)).toBe(false);
12
+ });
13
+ });
@@ -0,0 +1,20 @@
1
+ import { getActiveClient } from '../activeClient';
2
+ import { connectClient, disconnectClient } from '~/utils/tests';
3
+
4
+ describe('API: Active Client', () => {
5
+ afterAll(disconnectClient);
6
+
7
+ test('should got error message when activeClient is offline', () => {
8
+ try {
9
+ getActiveClient();
10
+ } catch (error) {
11
+ expect(String(error)).toContain('Error: Amity SDK (800000): There is no active client');
12
+ }
13
+ });
14
+
15
+ test('should get client when activeClient is online', async () => {
16
+ await connectClient();
17
+ const data = getActiveClient();
18
+ expect(data.userId).toBe('test');
19
+ });
20
+ });
@@ -0,0 +1,20 @@
1
+ import { getActiveUser } from '../activeUser';
2
+ import { connectClient, disconnectClient } from '~/utils/tests';
3
+
4
+ describe('API: Active User', () => {
5
+ afterAll(disconnectClient);
6
+
7
+ test('should got error message when client is offline', () => {
8
+ try {
9
+ getActiveUser();
10
+ } catch (error) {
11
+ expect(String(error)).toContain('Error: Amity SDK (800000): Connect client first');
12
+ }
13
+ });
14
+
15
+ test('should get active user when client is online', async () => {
16
+ await connectClient();
17
+ const data = getActiveUser();
18
+ expect(data.userId).toBe('test');
19
+ });
20
+ });
@@ -0,0 +1,33 @@
1
+ import { onPostApproved } from '../onPostApproved';
2
+ import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
3
+
4
+ describe('onPostApproved', () => {
5
+ beforeAll(async () => {
6
+ await connectClient();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await disconnectClient();
11
+ });
12
+
13
+ test('it should got event after post approved', () => {
14
+ const callback = jest.fn();
15
+ const unsub = onPostApproved(callback);
16
+ client.emitter.emit('post.approved', postPayload);
17
+
18
+ unsub();
19
+
20
+ expect(callback).toHaveBeenCalled();
21
+ expect(callback).toHaveBeenCalledWith(post11);
22
+ });
23
+
24
+ test('it should got nothing if we did unsubscribe before got event', () => {
25
+ const callback = jest.fn();
26
+ const unsub = onPostApproved(callback);
27
+
28
+ unsub();
29
+
30
+ client.emitter.emit('post.approved', postPayload);
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+ });
@@ -0,0 +1,33 @@
1
+ import { onPostCreated } from '../onPostCreated';
2
+ import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
3
+
4
+ describe('onPostCreated', () => {
5
+ beforeAll(async () => {
6
+ await connectClient();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await disconnectClient();
11
+ });
12
+
13
+ test('it should got event after post created', () => {
14
+ const callback = jest.fn();
15
+ const unsub = onPostCreated(callback);
16
+ client.emitter.emit('post.created', postPayload);
17
+
18
+ unsub();
19
+
20
+ expect(callback).toHaveBeenCalled();
21
+ expect(callback).toHaveBeenCalledWith(post11);
22
+ });
23
+
24
+ test('it should got nothing if we did unsubscribe before got event', () => {
25
+ const callback = jest.fn();
26
+ const unsub = onPostCreated(callback);
27
+
28
+ unsub();
29
+
30
+ client.emitter.emit('post.created', postPayload);
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+ });
@@ -0,0 +1,33 @@
1
+ import { onPostDeclined } from '../onPostDeclined';
2
+ import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
3
+
4
+ describe('onPostDeclined', () => {
5
+ beforeAll(async () => {
6
+ await connectClient();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await disconnectClient();
11
+ });
12
+
13
+ test('it should got event after post declined', () => {
14
+ const callback = jest.fn();
15
+ const unsub = onPostDeclined(callback);
16
+ client.emitter.emit('post.declined', postPayload);
17
+
18
+ unsub();
19
+
20
+ expect(callback).toHaveBeenCalled();
21
+ expect(callback).toHaveBeenCalledWith(post11);
22
+ });
23
+
24
+ test('it should got nothing if we did unsubscribe before got event', () => {
25
+ const callback = jest.fn();
26
+ const unsub = onPostDeclined(callback);
27
+
28
+ unsub();
29
+
30
+ client.emitter.emit('post.declined', postPayload);
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+ });
@@ -0,0 +1,33 @@
1
+ import { onPostDeleted } from '../onPostDeleted';
2
+ import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
3
+
4
+ describe('onPostDeleted', () => {
5
+ beforeAll(async () => {
6
+ await connectClient();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await disconnectClient();
11
+ });
12
+
13
+ test('it should got event after post deleted', () => {
14
+ const callback = jest.fn();
15
+ const unsub = onPostDeleted(callback);
16
+ client.emitter.emit('post.deleted', postPayload);
17
+
18
+ unsub();
19
+
20
+ expect(callback).toHaveBeenCalled();
21
+ expect(callback).toHaveBeenCalledWith(post11);
22
+ });
23
+
24
+ test('it should got nothing if we did unsubscribe before got event', () => {
25
+ const callback = jest.fn();
26
+ const unsub = onPostDeleted(callback);
27
+
28
+ unsub();
29
+
30
+ client.emitter.emit('post.deleted', postPayload);
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+ });
@@ -0,0 +1,33 @@
1
+ import { onPostFlagged } from '../onPostFlagged';
2
+ import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
3
+
4
+ describe('onPostFlagged', () => {
5
+ beforeAll(async () => {
6
+ await connectClient();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await disconnectClient();
11
+ });
12
+
13
+ test('it should got event after post flagged', () => {
14
+ const callback = jest.fn();
15
+ const unsub = onPostFlagged(callback);
16
+ client.emitter.emit('post.flagged', postPayload);
17
+
18
+ unsub();
19
+
20
+ expect(callback).toHaveBeenCalled();
21
+ expect(callback).toHaveBeenCalledWith(post11);
22
+ });
23
+
24
+ test('it should got nothing if we did unsubscribe before got event', () => {
25
+ const callback = jest.fn();
26
+ const unsub = onPostFlagged(callback);
27
+
28
+ unsub();
29
+
30
+ client.emitter.emit('post.flagged', postPayload);
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+ });
@@ -0,0 +1,40 @@
1
+ import { onPostReactionAdded } from '../onPostReactionAdded';
2
+ import {
3
+ client,
4
+ connectClient,
5
+ disconnectClient,
6
+ postPayload,
7
+ post11,
8
+ reaction11,
9
+ } from '~/utils/tests';
10
+
11
+ describe('onPostReactionAdded', () => {
12
+ beforeAll(async () => {
13
+ await connectClient();
14
+ });
15
+
16
+ afterAll(async () => {
17
+ await disconnectClient();
18
+ });
19
+
20
+ test('it should got event after add reaction to post', () => {
21
+ const callback = jest.fn();
22
+ const unsub = onPostReactionAdded(callback);
23
+ client.emitter.emit('post.addReaction', { ...postPayload, reactor: reaction11 });
24
+
25
+ unsub();
26
+
27
+ expect(callback).toHaveBeenCalled();
28
+ expect(callback).toHaveBeenCalledWith(post11);
29
+ });
30
+
31
+ test('it should got nothing if we did unsubscribe before got event', () => {
32
+ const callback = jest.fn();
33
+ const unsub = onPostReactionAdded(callback);
34
+
35
+ unsub();
36
+
37
+ client.emitter.emit('post.addReaction', { ...postPayload, reactor: reaction11 });
38
+ expect(callback).not.toHaveBeenCalled();
39
+ });
40
+ });
@@ -0,0 +1,40 @@
1
+ import { onPostReactionRemoved } from '../onPostReactionRemoved';
2
+ import {
3
+ client,
4
+ connectClient,
5
+ disconnectClient,
6
+ postPayload,
7
+ post11,
8
+ reaction11,
9
+ } from '~/utils/tests';
10
+
11
+ describe('onPostReactionRemoved', () => {
12
+ beforeAll(async () => {
13
+ await connectClient();
14
+ });
15
+
16
+ afterAll(async () => {
17
+ await disconnectClient();
18
+ });
19
+
20
+ test('it should got event after reaction got removed from post', () => {
21
+ const callback = jest.fn();
22
+ const unsub = onPostReactionRemoved(callback);
23
+ client.emitter.emit('post.removeReaction', { ...postPayload, reactor: reaction11 });
24
+
25
+ unsub();
26
+
27
+ expect(callback).toHaveBeenCalled();
28
+ expect(callback).toHaveBeenCalledWith(post11);
29
+ });
30
+
31
+ test('it should got nothing if we did unsubscribe before got event', () => {
32
+ const callback = jest.fn();
33
+ const unsub = onPostReactionRemoved(callback);
34
+
35
+ unsub();
36
+
37
+ client.emitter.emit('post.removeReaction', { ...postPayload, reactor: reaction11 });
38
+ expect(callback).not.toHaveBeenCalled();
39
+ });
40
+ });
@@ -0,0 +1,33 @@
1
+ import { onPostUnflagged } from '../onPostUnflagged';
2
+ import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
3
+
4
+ describe('onPostUnflagged', () => {
5
+ beforeAll(async () => {
6
+ await connectClient();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await disconnectClient();
11
+ });
12
+
13
+ test('it should got event after post unflagged', () => {
14
+ const callback = jest.fn();
15
+ const unsub = onPostUnflagged(callback);
16
+ client.emitter.emit('post.unflagged', postPayload);
17
+
18
+ unsub();
19
+
20
+ expect(callback).toHaveBeenCalled();
21
+ expect(callback).toHaveBeenCalledWith(post11);
22
+ });
23
+
24
+ test('it should got nothing if we did unsubscribe before got event', () => {
25
+ const callback = jest.fn();
26
+ const unsub = onPostUnflagged(callback);
27
+
28
+ unsub();
29
+
30
+ client.emitter.emit('post.unflagged', postPayload);
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+ });
@@ -0,0 +1,33 @@
1
+ import { onPostUpdated } from '../onPostUpdated';
2
+ import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
3
+
4
+ describe('onPostUpdated', () => {
5
+ beforeAll(async () => {
6
+ await connectClient();
7
+ });
8
+
9
+ afterAll(async () => {
10
+ await disconnectClient();
11
+ });
12
+
13
+ test('it should got event after post updated', () => {
14
+ const callback = jest.fn();
15
+ const unsub = onPostUpdated(callback);
16
+ client.emitter.emit('post.updated', postPayload);
17
+
18
+ unsub();
19
+
20
+ expect(callback).toHaveBeenCalled();
21
+ expect(callback).toHaveBeenCalledWith(post11);
22
+ });
23
+
24
+ test('it should got nothing if we did unsubscribe before got event', () => {
25
+ const callback = jest.fn();
26
+ const unsub = onPostUpdated(callback);
27
+
28
+ unsub();
29
+
30
+ client.emitter.emit('post.updated', postPayload);
31
+ expect(callback).not.toHaveBeenCalled();
32
+ });
33
+ });
@@ -89,6 +89,10 @@ export const livePosts = (
89
89
 
90
90
  posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
91
91
 
92
+ if (params.tags) {
93
+ posts = posts.filter(p => p.tags?.some(t => params.tags?.includes(t)));
94
+ }
95
+
92
96
  callback({
93
97
  onNextPage: onFetch,
94
98
  data: posts,
@@ -108,6 +112,12 @@ export const livePosts = (
108
112
  collection.data = [...new Set([post.postId, ...collection.data])];
109
113
  } else if (['onDelete', 'onDeclined'].includes(action)) {
110
114
  collection.data = collection.data.filter(p => p !== post.postId);
115
+
116
+ /*
117
+ * if isDeleted is true, collection should add deleted items to the
118
+ * begining of the collection
119
+ */
120
+ if (params.isDeleted) collection.data.unshift(post.postId);
111
121
  }
112
122
 
113
123
  pushToCache(cacheKey, collection);