@capillarytech/creatives-library 7.14.37 → 7.14.38
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,82 +0,0 @@
|
|
|
1
|
-
import { expectSaga } from "redux-saga-test-plan";
|
|
2
|
-
import { take, cancel, takeLatest } from "redux-saga/effects";
|
|
3
|
-
import * as matchers from "redux-saga-test-plan/matchers";
|
|
4
|
-
import { LOCATION_CHANGE } from "react-router-redux";
|
|
5
|
-
import { throwError } from "redux-saga-test-plan/providers";
|
|
6
|
-
import { createMockTask } from "redux-saga/utils";
|
|
7
|
-
import * as types from "../constants";
|
|
8
|
-
import { watchAiSuggestions, getAiSuggestions } from "../sagas";
|
|
9
|
-
import * as Api from "../../../../services/api";
|
|
10
|
-
|
|
11
|
-
describe("getAiSuggestions saga", () => {
|
|
12
|
-
it("Should handle valid response from api", () => {
|
|
13
|
-
const successCallback = () => {};
|
|
14
|
-
const failureCallback = () => {};
|
|
15
|
-
const action = {
|
|
16
|
-
type: types.GET_AI_SUGGESTIONS,
|
|
17
|
-
prompt: {},
|
|
18
|
-
successCallback,
|
|
19
|
-
failureCallback,
|
|
20
|
-
};
|
|
21
|
-
expectSaga(getAiSuggestions, action)
|
|
22
|
-
.provide([
|
|
23
|
-
[
|
|
24
|
-
matchers.call.fn(Api.getAiSuggestions),
|
|
25
|
-
{
|
|
26
|
-
success: true,
|
|
27
|
-
status: {
|
|
28
|
-
isError: false,
|
|
29
|
-
code: 200,
|
|
30
|
-
message: "success",
|
|
31
|
-
},
|
|
32
|
-
message: "Meta data fetched successfully",
|
|
33
|
-
response: {
|
|
34
|
-
"https://response.com": 1400,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
[matchers.call.fn(successCallback)],
|
|
39
|
-
])
|
|
40
|
-
.run();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("Should handles error thrown from api", () => {
|
|
44
|
-
const successCallback = () => {};
|
|
45
|
-
const failureCallback = () => {};
|
|
46
|
-
const action = {
|
|
47
|
-
type: types.GET_AI_SUGGESTIONS,
|
|
48
|
-
prompt: {},
|
|
49
|
-
successCallback,
|
|
50
|
-
failureCallback,
|
|
51
|
-
};
|
|
52
|
-
expectSaga(getAiSuggestions, action)
|
|
53
|
-
.provide([[matchers.call.fn(Api.getAiSuggestions), throwError()]])
|
|
54
|
-
.run();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("watchAiSuggestions saga", () => {
|
|
59
|
-
let generator = null;
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
generator = watchAiSuggestions();
|
|
62
|
-
});
|
|
63
|
-
it("Should handle valid response from api", () => {
|
|
64
|
-
const progress1 = generator.next();
|
|
65
|
-
const mockTask = takeLatest(types.GET_AI_SUGGESTIONS, getAiSuggestions);
|
|
66
|
-
expect(progress1.value).toEqual(mockTask);
|
|
67
|
-
const progress2 = generator.next();
|
|
68
|
-
expect(progress2.value).toEqual(take(LOCATION_CHANGE));
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("Should handle LOCATION_CHANGE action and cancel the watcher", () => {
|
|
72
|
-
generator = watchAiSuggestions();
|
|
73
|
-
const mockTask = createMockTask();
|
|
74
|
-
|
|
75
|
-
expect(generator.next().value).toEqual(
|
|
76
|
-
takeLatest(types.GET_AI_SUGGESTIONS, getAiSuggestions)
|
|
77
|
-
);
|
|
78
|
-
expect(generator.next(mockTask).value).toEqual(take(LOCATION_CHANGE));
|
|
79
|
-
expect(generator.next().value).toEqual(cancel(mockTask));
|
|
80
|
-
expect(generator.next().done).toEqual(true);
|
|
81
|
-
});
|
|
82
|
-
});
|