1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | const upgrade = require("./upgrade");
|
8 | const models = require("@conversationlearner/models");
|
9 | describe('upgrade', () => {
|
10 | describe('getActionPayload', () => {
|
11 | test('given single arguments payload callback with argument moved to either logic or render function return a new payload with argument in respective arguments list', () => {
|
12 |
|
13 | const legacyActionPayload = {
|
14 | payload: 'payload',
|
15 | arguments: [
|
16 | {
|
17 | parameter: "logicArg",
|
18 | value: {
|
19 | json: {}
|
20 | }
|
21 | },
|
22 | {
|
23 | parameter: "renderArg",
|
24 | value: {
|
25 | json: {}
|
26 | }
|
27 | },
|
28 | {
|
29 | parameter: "sharedArg",
|
30 | value: {
|
31 | json: {}
|
32 | }
|
33 | }
|
34 | ]
|
35 | };
|
36 | const callback = {
|
37 | name: "myCallback",
|
38 | logicArguments: [
|
39 | "logicArg",
|
40 | "sharedArg"
|
41 | ],
|
42 | isLogicFunctionProvided: true,
|
43 | renderArguments: [
|
44 | "renderArg",
|
45 | "sharedArg"
|
46 | ],
|
47 | isRenderFunctionProvided: true
|
48 | };
|
49 |
|
50 | const actionPayload = upgrade.getActionPayload(legacyActionPayload, callback);
|
51 |
|
52 | expect(actionPayload.payload).toEqual(legacyActionPayload.payload);
|
53 | expect(actionPayload.logicArguments.some(la => la.parameter === legacyActionPayload.arguments[0].parameter)).toBeTruthy();
|
54 | });
|
55 | test('given single arguments payload callback with arguments not found in either logic or render it will be dropped', () => {
|
56 |
|
57 | const legacyActionPayload = {
|
58 | payload: 'payload',
|
59 | arguments: [
|
60 | {
|
61 | parameter: "arg1",
|
62 | value: {
|
63 | json: {}
|
64 | }
|
65 | }
|
66 | ]
|
67 | };
|
68 | const callback = {
|
69 | name: "myCallback",
|
70 | logicArguments: [],
|
71 | isLogicFunctionProvided: true,
|
72 | renderArguments: [],
|
73 | isRenderFunctionProvided: true,
|
74 | };
|
75 |
|
76 | const actionPayload = upgrade.getActionPayload(legacyActionPayload, callback);
|
77 |
|
78 | expect(actionPayload.payload).toEqual(legacyActionPayload.payload);
|
79 | expect(actionPayload.logicArguments.some(la => la.parameter === legacyActionPayload.arguments[0].parameter)).toBeFalsy();
|
80 | expect(actionPayload.renderArguments.some(la => la.parameter === legacyActionPayload.arguments[0].parameter)).toBeFalsy();
|
81 | });
|
82 | });
|
83 | describe('getActionChangeResult', () => {
|
84 | test('given a action without need to be changed, return it unmodified with no changes', () => {
|
85 |
|
86 | const action = {
|
87 | actionId: 'fakeActionId',
|
88 | actionType: models.ActionTypes.API_LOCAL,
|
89 | createdDateTime: new Date().toJSON(),
|
90 | isTerminal: false,
|
91 | negativeEntities: [],
|
92 | negativeConditions: [],
|
93 | payload: JSON.stringify({
|
94 | payload: "myCallback",
|
95 | logicArguments: [
|
96 | {
|
97 | parameter: "someArg",
|
98 | value: {
|
99 | json: {}
|
100 | }
|
101 | }
|
102 | ],
|
103 | renderArguments: [
|
104 | {
|
105 | parameter: "otherArg",
|
106 | value: {
|
107 | json: {}
|
108 | }
|
109 | }
|
110 | ]
|
111 | }),
|
112 | requiredEntities: [],
|
113 | requiredConditions: [],
|
114 | requiredEntitiesFromPayload: [],
|
115 | suggestedEntity: undefined,
|
116 | version: 0,
|
117 | packageCreationId: 0,
|
118 | packageDeletionId: 0,
|
119 | entityId: undefined,
|
120 | enumValueId: undefined,
|
121 | };
|
122 | const callbackMap = {};
|
123 |
|
124 | const defaultActionChangeResult = upgrade.getDefaultChangeResult(action);
|
125 | const actionChangeResult = upgrade.getActionChangeResult(action, callbackMap);
|
126 |
|
127 | expect(actionChangeResult).toEqual(defaultActionChangeResult);
|
128 | });
|
129 | test('given an old action return it with list of change descriptions', () => {
|
130 |
|
131 | const action = {
|
132 | actionId: 'fakeActionId',
|
133 | actionType: models.ActionTypes.API_LOCAL,
|
134 | createdDateTime: new Date().toJSON(),
|
135 | isTerminal: false,
|
136 | negativeEntities: [],
|
137 | negativeConditions: [],
|
138 | payload: JSON.stringify({
|
139 | payload: "myCallback",
|
140 | arguments: [
|
141 | {
|
142 | parameter: "logicArg",
|
143 | value: {
|
144 | json: {}
|
145 | }
|
146 | },
|
147 | {
|
148 | parameter: "renderArg",
|
149 | value: {
|
150 | json: {}
|
151 | }
|
152 | }
|
153 | ]
|
154 | }),
|
155 | requiredEntities: [],
|
156 | requiredConditions: [],
|
157 | requiredEntitiesFromPayload: [],
|
158 | suggestedEntity: undefined,
|
159 | version: 0,
|
160 | packageCreationId: 0,
|
161 | packageDeletionId: 0,
|
162 | entityId: undefined,
|
163 | enumValueId: undefined,
|
164 | };
|
165 | const callbackMap = {};
|
166 |
|
167 | const actionChangeResult = upgrade.getActionChangeResult(action, callbackMap);
|
168 |
|
169 | expect(actionChangeResult.isChanged).toBe(true);
|
170 | expect(actionChangeResult.changes.length).toBeGreaterThan(0);
|
171 | });
|
172 | });
|
173 | describe('getAppDefinitionChange', () => {
|
174 | test('given app definition without changes return object as is without changes', () => {
|
175 |
|
176 | const appDefinition = {
|
177 | actions: [],
|
178 | entities: [],
|
179 | trainDialogs: []
|
180 | };
|
181 |
|
182 | const appChange = upgrade.default(appDefinition, {});
|
183 |
|
184 | expect(appChange.isChanged).toBe(false);
|
185 | expect(appChange.currentAppDefinition).toEqual(appDefinition);
|
186 | });
|
187 | test('given app definition without changes return object as is without changes', () => {
|
188 |
|
189 | const action = {
|
190 | actionId: 'fakeActionId',
|
191 | actionType: models.ActionTypes.API_LOCAL,
|
192 | createdDateTime: new Date().toJSON(),
|
193 | isTerminal: false,
|
194 | negativeEntities: [],
|
195 | negativeConditions: [],
|
196 | payload: JSON.stringify({
|
197 | payload: "myCallback",
|
198 | arguments: [
|
199 | {
|
200 | parameter: "logicArg",
|
201 | value: {
|
202 | json: {}
|
203 | }
|
204 | },
|
205 | {
|
206 | parameter: "renderArg",
|
207 | value: {
|
208 | json: {}
|
209 | }
|
210 | }
|
211 | ]
|
212 | }),
|
213 | requiredEntities: [],
|
214 | requiredConditions: [],
|
215 | requiredEntitiesFromPayload: [],
|
216 | suggestedEntity: undefined,
|
217 | version: 0,
|
218 | packageCreationId: 0,
|
219 | packageDeletionId: 0,
|
220 | entityId: undefined,
|
221 | enumValueId: undefined,
|
222 | };
|
223 | const appDefinition = {
|
224 | actions: [
|
225 | action
|
226 | ],
|
227 | entities: [],
|
228 | trainDialogs: []
|
229 | };
|
230 |
|
231 | const appChange = upgrade.default(appDefinition, {});
|
232 |
|
233 | expect(appChange.isChanged).toBe(true);
|
234 | expect(appChange.currentAppDefinition).toEqual(appDefinition);
|
235 | });
|
236 | });
|
237 | });
|
238 |
|
\ | No newline at end of file |