How to use wrapParams method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

plain-client.js

Source: plain-client.js Github

copy
1function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
3function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
5function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
7import { ALPHA_FEATURE_WORKFLOWS } from '../adapters/REST/endpoints/workflow-definition';
8import { omitAndDeleteField as _omitAndDeleteField } from '../methods/content-type';
9import { wrap } from './wrappers/wrap';
10
11/**
12 * @private
13 */
14export var createPlainClient = function createPlainClient(makeRequest, defaults, alphaFeatures) {
15  var wrapParams = {
16    makeRequest: makeRequest,
17    defaults: defaults
18  };
19  return _objectSpread({
20    raw: {
21      getDefaultParams: function getDefaultParams() {
22        return defaults;
23      },
24      get: function get(url, config) {
25        return makeRequest({
26          entityType: 'Http',
27          action: 'get',
28          params: {
29            url: url,
30            config: config
31          }
32        });
33      },
34      patch: function patch(url, payload, config) {
35        return makeRequest({
36          entityType: 'Http',
37          action: 'patch',
38          params: {
39            url: url,
40            config: config
41          },
42          payload: payload
43        });
44      },
45      post: function post(url, payload, config) {
46        return makeRequest({
47          entityType: 'Http',
48          action: 'post',
49          params: {
50            url: url,
51            config: config
52          },
53          payload: payload
54        });
55      },
56      put: function put(url, payload, config) {
57        return makeRequest({
58          entityType: 'Http',
59          action: 'put',
60          params: {
61            url: url,
62            config: config
63          },
64          payload: payload
65        });
66      },
67      "delete": function _delete(url, config) {
68        return makeRequest({
69          entityType: 'Http',
70          action: 'delete',
71          params: {
72            url: url,
73            config: config
74          }
75        });
76      },
77      http: function http(url, config) {
78        return makeRequest({
79          entityType: 'Http',
80          action: 'request',
81          params: {
82            url: url,
83            config: config
84          }
85        });
86      }
87    },
88    appAction: {
89      get: wrap(wrapParams, 'AppAction', 'get'),
90      getMany: wrap(wrapParams, 'AppAction', 'getMany'),
91      "delete": wrap(wrapParams, 'AppAction', 'delete'),
92      create: wrap(wrapParams, 'AppAction', 'create'),
93      update: wrap(wrapParams, 'AppAction', 'update')
94    },
95    appActionCall: {
96      create: wrap(wrapParams, 'AppActionCall', 'create')
97    },
98    appBundle: {
99      get: wrap(wrapParams, 'AppBundle', 'get'),
100      getMany: wrap(wrapParams, 'AppBundle', 'getMany'),
101      "delete": wrap(wrapParams, 'AppBundle', 'delete'),
102      create: wrap(wrapParams, 'AppBundle', 'create')
103    },
104    appDetails: {
105      upsert: wrap(wrapParams, 'AppDetails', 'upsert'),
106      get: wrap(wrapParams, 'AppDetails', 'get'),
107      "delete": wrap(wrapParams, 'AppDetails', 'delete')
108    },
109    appSignedRequest: {
110      create: wrap(wrapParams, 'AppSignedRequest', 'create')
111    },
112    appSigningSecret: {
113      upsert: wrap(wrapParams, 'AppSigningSecret', 'upsert'),
114      get: wrap(wrapParams, 'AppSigningSecret', 'get'),
115      "delete": wrap(wrapParams, 'AppSigningSecret', 'delete')
116    },
117    editorInterface: {
118      get: wrap(wrapParams, 'EditorInterface', 'get'),
119      getMany: wrap(wrapParams, 'EditorInterface', 'getMany'),
120      update: wrap(wrapParams, 'EditorInterface', 'update')
121    },
122    space: {
123      get: wrap(wrapParams, 'Space', 'get'),
124      getMany: wrap(wrapParams, 'Space', 'getMany'),
125      update: wrap(wrapParams, 'Space', 'update'),
126      "delete": wrap(wrapParams, 'Space', 'delete'),
127      create: wrap(wrapParams, 'Space', 'create')
128    },
129    environment: {
130      get: wrap(wrapParams, 'Environment', 'get'),
131      getMany: wrap(wrapParams, 'Environment', 'getMany'),
132      create: wrap(wrapParams, 'Environment', 'create'),
133      createWithId: wrap(wrapParams, 'Environment', 'createWithId'),
134      update: wrap(wrapParams, 'Environment', 'update'),
135      "delete": wrap(wrapParams, 'Environment', 'delete')
136    },
137    environmentAlias: {
138      get: wrap(wrapParams, 'EnvironmentAlias', 'get'),
139      getMany: wrap(wrapParams, 'EnvironmentAlias', 'getMany'),
140      createWithId: wrap(wrapParams, 'EnvironmentAlias', 'createWithId'),
141      update: wrap(wrapParams, 'EnvironmentAlias', 'update'),
142      "delete": wrap(wrapParams, 'EnvironmentAlias', 'delete')
143    },
144    bulkAction: {
145      get: wrap(wrapParams, 'BulkAction', 'get'),
146      publish: wrap(wrapParams, 'BulkAction', 'publish'),
147      unpublish: wrap(wrapParams, 'BulkAction', 'unpublish'),
148      validate: wrap(wrapParams, 'BulkAction', 'validate')
149    },
150    comment: {
151      get: wrap(wrapParams, 'Comment', 'get'),
152      getAll: wrap(wrapParams, 'Comment', 'getAll'),
153      create: wrap(wrapParams, 'Comment', 'create'),
154      update: wrap(wrapParams, 'Comment', 'update'),
155      "delete": wrap(wrapParams, 'Comment', 'delete')
156    },
157    contentType: {
158      get: wrap(wrapParams, 'ContentType', 'get'),
159      getMany: wrap(wrapParams, 'ContentType', 'getMany'),
160      update: wrap(wrapParams, 'ContentType', 'update'),
161      "delete": wrap(wrapParams, 'ContentType', 'delete'),
162      publish: wrap(wrapParams, 'ContentType', 'publish'),
163      unpublish: wrap(wrapParams, 'ContentType', 'unpublish'),
164      create: wrap(wrapParams, 'ContentType', 'create'),
165      createWithId: wrap(wrapParams, 'ContentType', 'createWithId'),
166      omitAndDeleteField: function omitAndDeleteField(params, contentType, fieldId) {
167        return _omitAndDeleteField(makeRequest, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {
168          fieldId: fieldId
169        }), contentType);
170      }
171    },
172    user: {
173      getManyForSpace: wrap(wrapParams, 'User', 'getManyForSpace'),
174      getForSpace: wrap(wrapParams, 'User', 'getForSpace'),
175      getCurrent: wrap(wrapParams, 'User', 'getCurrent'),
176      getForOrganization: wrap(wrapParams, 'User', 'getForOrganization'),
177      getManyForOrganization: wrap(wrapParams, 'User', 'getManyForOrganization')
178    },
179    task: {
180      get: wrap(wrapParams, 'Task', 'get'),
181      getAll: wrap(wrapParams, 'Task', 'getAll'),
182      create: wrap(wrapParams, 'Task', 'create'),
183      update: wrap(wrapParams, 'Task', 'update'),
184      "delete": wrap(wrapParams, 'Task', 'delete')
185    },
186    entry: {
187      getMany: wrap(wrapParams, 'Entry', 'getMany'),
188      get: wrap(wrapParams, 'Entry', 'get'),
189      update: wrap(wrapParams, 'Entry', 'update'),
190      patch: wrap(wrapParams, 'Entry', 'patch'),
191      "delete": wrap(wrapParams, 'Entry', 'delete'),
192      publish: wrap(wrapParams, 'Entry', 'publish'),
193      unpublish: wrap(wrapParams, 'Entry', 'unpublish'),
194      archive: wrap(wrapParams, 'Entry', 'archive'),
195      unarchive: wrap(wrapParams, 'Entry', 'unarchive'),
196      create: wrap(wrapParams, 'Entry', 'create'),
197      createWithId: wrap(wrapParams, 'Entry', 'createWithId'),
198      references: wrap(wrapParams, 'Entry', 'references')
199    },
200    asset: {
201      getMany: wrap(wrapParams, 'Asset', 'getMany'),
202      get: wrap(wrapParams, 'Asset', 'get'),
203      update: wrap(wrapParams, 'Asset', 'update'),
204      "delete": wrap(wrapParams, 'Asset', 'delete'),
205      publish: wrap(wrapParams, 'Asset', 'publish'),
206      unpublish: wrap(wrapParams, 'Asset', 'unpublish'),
207      archive: wrap(wrapParams, 'Asset', 'archive'),
208      unarchive: wrap(wrapParams, 'Asset', 'unarchive'),
209      create: wrap(wrapParams, 'Asset', 'create'),
210      createWithId: wrap(wrapParams, 'Asset', 'createWithId'),
211      createFromFiles: wrap(wrapParams, 'Asset', 'createFromFiles'),
212      processForAllLocales: function processForAllLocales(params, asset, options) {
213        return makeRequest({
214          entityType: 'Asset',
215          action: 'processForAllLocales',
216          params: _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {
217            options: options,
218            asset: asset
219          })
220        });
221      },
222      processForLocale: function processForLocale(params, asset, locale, options) {
223        return makeRequest({
224          entityType: 'Asset',
225          action: 'processForLocale',
226          params: _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {
227            locale: locale,
228            asset: asset,
229            options: options
230          })
231        });
232      }
233    },
234    appUpload: {
235      get: wrap(wrapParams, 'AppUpload', 'get'),
236      "delete": wrap(wrapParams, 'AppUpload', 'delete'),
237      create: wrap(wrapParams, 'AppUpload', 'create')
238    },
239    assetKey: {
240      create: wrap(wrapParams, 'AssetKey', 'create')
241    },
242    upload: {
243      get: wrap(wrapParams, 'Upload', 'get'),
244      create: wrap(wrapParams, 'Upload', 'create'),
245      "delete": wrap(wrapParams, 'Upload', 'delete')
246    },
247    locale: {
248      get: wrap(wrapParams, 'Locale', 'get'),
249      getMany: wrap(wrapParams, 'Locale', 'getMany'),
250      "delete": wrap(wrapParams, 'Locale', 'delete'),
251      update: wrap(wrapParams, 'Locale', 'update'),
252      create: wrap(wrapParams, 'Locale', 'create')
253    },
254    personalAccessToken: {
255      get: wrap(wrapParams, 'PersonalAccessToken', 'get'),
256      getMany: wrap(wrapParams, 'PersonalAccessToken', 'getMany'),
257      create: function create(data, headers) {
258        return makeRequest({
259          entityType: 'PersonalAccessToken',
260          action: 'create',
261          params: {},
262          headers: headers,
263          payload: data
264        });
265      },
266      revoke: wrap(wrapParams, 'PersonalAccessToken', 'revoke')
267    },
268    usage: {
269      getManyForSpace: wrap(wrapParams, 'Usage', 'getManyForSpace'),
270      getManyForOrganization: wrap(wrapParams, 'Usage', 'getManyForOrganization')
271    },
272    release: {
273      get: wrap(wrapParams, 'Release', 'get'),
274      query: wrap(wrapParams, 'Release', 'query'),
275      create: wrap(wrapParams, 'Release', 'create'),
276      update: wrap(wrapParams, 'Release', 'update'),
277      "delete": wrap(wrapParams, 'Release', 'delete'),
278      publish: wrap(wrapParams, 'Release', 'publish'),
279      unpublish: wrap(wrapParams, 'Release', 'unpublish'),
280      validate: wrap(wrapParams, 'Release', 'validate')
281    },
282    releaseAction: {
283      get: wrap(wrapParams, 'ReleaseAction', 'get'),
284      queryForRelease: wrap(wrapParams, 'ReleaseAction', 'queryForRelease')
285    },
286    role: {
287      get: wrap(wrapParams, 'Role', 'get'),
288      getMany: wrap(wrapParams, 'Role', 'getMany'),
289      create: wrap(wrapParams, 'Role', 'create'),
290      createWithId: wrap(wrapParams, 'Role', 'createWithId'),
291      update: wrap(wrapParams, 'Role', 'update'),
292      "delete": wrap(wrapParams, 'Role', 'delete')
293    },
294    scheduledActions: {
295      get: wrap(wrapParams, 'ScheduledAction', 'get'),
296      getMany: wrap(wrapParams, 'ScheduledAction', 'getMany'),
297      create: wrap(wrapParams, 'ScheduledAction', 'create'),
298      "delete": wrap(wrapParams, 'ScheduledAction', 'delete'),
299      update: wrap(wrapParams, 'ScheduledAction', 'update')
300    },
301    previewApiKey: {
302      get: wrap(wrapParams, 'PreviewApiKey', 'get'),
303      getMany: wrap(wrapParams, 'PreviewApiKey', 'getMany')
304    },
305    apiKey: {
306      get: wrap(wrapParams, 'ApiKey', 'get'),
307      getMany: wrap(wrapParams, 'ApiKey', 'getMany'),
308      create: wrap(wrapParams, 'ApiKey', 'create'),
309      createWithId: wrap(wrapParams, 'ApiKey', 'createWithId'),
310      update: wrap(wrapParams, 'ApiKey', 'update'),
311      "delete": wrap(wrapParams, 'ApiKey', 'delete')
312    },
313    appDefinition: {
314      get: wrap(wrapParams, 'AppDefinition', 'get'),
315      getMany: wrap(wrapParams, 'AppDefinition', 'getMany'),
316      create: wrap(wrapParams, 'AppDefinition', 'create'),
317      update: wrap(wrapParams, 'AppDefinition', 'update'),
318      "delete": wrap(wrapParams, 'AppDefinition', 'delete')
319    },
320    appInstallation: {
321      get: wrap(wrapParams, 'AppInstallation', 'get'),
322      getMany: wrap(wrapParams, 'AppInstallation', 'getMany'),
323      upsert: wrap(wrapParams, 'AppInstallation', 'upsert'),
324      "delete": wrap(wrapParams, 'AppInstallation', 'delete')
325    },
326    extension: {
327      get: wrap(wrapParams, 'Extension', 'get'),
328      getMany: wrap(wrapParams, 'Extension', 'getMany'),
329      create: wrap(wrapParams, 'Extension', 'create'),
330      createWithId: wrap(wrapParams, 'Extension', 'createWithId'),
331      update: wrap(wrapParams, 'Extension', 'update'),
332      "delete": wrap(wrapParams, 'Extension', 'delete')
333    },
334    webhook: {
335      get: wrap(wrapParams, 'Webhook', 'get'),
336      getMany: wrap(wrapParams, 'Webhook', 'getMany'),
337      getHealthStatus: wrap(wrapParams, 'Webhook', 'getHealthStatus'),
338      getCallDetails: wrap(wrapParams, 'Webhook', 'getCallDetails'),
339      getManyCallDetails: wrap(wrapParams, 'Webhook', 'getManyCallDetails'),
340      create: wrap(wrapParams, 'Webhook', 'create'),
341      update: wrap(wrapParams, 'Webhook', 'update'),
342      "delete": wrap(wrapParams, 'Webhook', 'delete')
343    },
344    snapshot: {
345      getManyForEntry: wrap(wrapParams, 'Snapshot', 'getManyForEntry'),
346      getForEntry: wrap(wrapParams, 'Snapshot', 'getForEntry'),
347      getManyForContentType: wrap(wrapParams, 'Snapshot', 'getManyForContentType'),
348      getForContentType: wrap(wrapParams, 'Snapshot', 'getForContentType')
349    },
350    tag: {
351      get: wrap(wrapParams, 'Tag', 'get'),
352      getMany: wrap(wrapParams, 'Tag', 'getMany'),
353      createWithId: wrap(wrapParams, 'Tag', 'createWithId'),
354      update: wrap(wrapParams, 'Tag', 'update'),
355      "delete": wrap(wrapParams, 'Tag', 'delete')
356    },
357    organization: {
358      getAll: wrap(wrapParams, 'Organization', 'getMany'),
359      get: wrap(wrapParams, 'Organization', 'get')
360    },
361    organizationInvitation: {
362      get: wrap(wrapParams, 'OrganizationInvitation', 'get'),
363      create: wrap(wrapParams, 'OrganizationInvitation', 'create')
364    },
365    organizationMembership: {
366      get: wrap(wrapParams, 'OrganizationMembership', 'get'),
367      getMany: wrap(wrapParams, 'OrganizationMembership', 'getMany'),
368      update: wrap(wrapParams, 'OrganizationMembership', 'update'),
369      "delete": wrap(wrapParams, 'OrganizationMembership', 'delete')
370    },
371    spaceMember: {
372      get: wrap(wrapParams, 'SpaceMember', 'get'),
373      getMany: wrap(wrapParams, 'SpaceMember', 'getMany')
374    },
375    spaceMembership: {
376      get: wrap(wrapParams, 'SpaceMembership', 'get'),
377      getMany: wrap(wrapParams, 'SpaceMembership', 'getMany'),
378      getForOrganization: wrap(wrapParams, 'SpaceMembership', 'getForOrganization'),
379      getManyForOrganization: wrap(wrapParams, 'SpaceMembership', 'getManyForOrganization'),
380      create: wrap(wrapParams, 'SpaceMembership', 'create'),
381      createWithId: wrap(wrapParams, 'SpaceMembership', 'createWithId'),
382      update: wrap(wrapParams, 'SpaceMembership', 'update'),
383      "delete": wrap(wrapParams, 'SpaceMembership', 'delete')
384    },
385    team: {
386      get: wrap(wrapParams, 'Team', 'get'),
387      getMany: wrap(wrapParams, 'Team', 'getMany'),
388      getManyForSpace: wrap(wrapParams, 'Team', 'getManyForSpace'),
389      create: wrap(wrapParams, 'Team', 'create'),
390      update: wrap(wrapParams, 'Team', 'update'),
391      "delete": wrap(wrapParams, 'Team', 'delete')
392    },
393    teamMembership: {
394      get: wrap(wrapParams, 'TeamMembership', 'get'),
395      getManyForOrganization: wrap(wrapParams, 'TeamMembership', 'getManyForOrganization'),
396      getManyForTeam: wrap(wrapParams, 'TeamMembership', 'getManyForTeam'),
397      create: wrap(wrapParams, 'TeamMembership', 'create'),
398      update: wrap(wrapParams, 'TeamMembership', 'update'),
399      "delete": wrap(wrapParams, 'TeamMembership', 'delete')
400    },
401    teamSpaceMembership: {
402      get: wrap(wrapParams, 'TeamSpaceMembership', 'get'),
403      getMany: wrap(wrapParams, 'TeamSpaceMembership', 'getMany'),
404      getForOrganization: wrap(wrapParams, 'TeamSpaceMembership', 'getForOrganization'),
405      getManyForOrganization: wrap(wrapParams, 'TeamSpaceMembership', 'getManyForOrganization'),
406      create: wrap(wrapParams, 'TeamSpaceMembership', 'create'),
407      update: wrap(wrapParams, 'TeamSpaceMembership', 'update'),
408      "delete": wrap(wrapParams, 'TeamSpaceMembership', 'delete')
409    }
410  }, addAlphaFeatures(makeRequest, defaults, alphaFeatures));
411};
412
413var addAlphaFeatures = function addAlphaFeatures(makeRequest, defaults, alphaFeatures) {
414  var wrapParams = {
415    makeRequest: makeRequest,
416    defaults: defaults
417  };
418  var alphaInterface = {};
419
420  if (alphaFeatures !== null && alphaFeatures !== void 0 && alphaFeatures.includes(ALPHA_FEATURE_WORKFLOWS)) {
421    alphaInterface.workflowDefinition = {
422      get: wrap(wrapParams, 'WorkflowDefinition', 'get'),
423      getMany: wrap(wrapParams, 'WorkflowDefinition', 'getMany'),
424      create: wrap(wrapParams, 'WorkflowDefinition', 'create'),
425      update: wrap(wrapParams, 'WorkflowDefinition', 'update'),
426      "delete": wrap(wrapParams, 'WorkflowDefinition', 'delete')
427    };
428    alphaInterface.workflow = {
429      getMany: wrap(wrapParams, 'Workflow', 'getMany'),
430      create: wrap(wrapParams, 'Workflow', 'create'),
431      update: wrap(wrapParams, 'Workflow', 'update'),
432      "delete": wrap(wrapParams, 'Workflow', 'delete'),
433      complete: wrap(wrapParams, 'Workflow', 'complete')
434    };
435    alphaInterface.workflowsChangelog = {
436      getMany: wrap(wrapParams, 'WorkflowsChangelog', 'getMany')
437    };
438  }
439
440  return alphaInterface;
441};
Full Screen

use-async.js

Source: use-async.js Github

copy
1import { ref, reactive, watch,unref } from "@vue/composition-api";
2
3export default function useAsync(promiseFnc, params) {
4  const wrapPromiseFn = ref(promiseFnc);
5  const wrapParams = ref(params);
6
7  const state = reactive({
8    isLoading: false,
9    error: null,
10    result: null,
11    retry_attempts: 0,
12    retry: () => {
13      state.retry_attempts++;
14      const origPromiseFn = unref(wrapPromiseFn);
15      wrapPromiseFn.value = async (params) => origPromiseFn(params);
16    },
17  });
18
19  const watched = [wrapPromiseFn, wrapParams];
20
21  watch(
22    watched,
23    async ([promiseFnc, wrapParams]) => {
24      state.isLoading = true;
25      state.error = null;
26
27      try {
28        console.log(wrapParams)
29        const data = await promiseFnc(wrapParams);
30        state.result = data;
31      } catch (error) {
32        console.log(error)
33        state.error = error;
34      } finally {
35        state.isLoading = false;
36      }
37    },
38    { immediate: true }
39  );
40
41  return state;
42}
43
Full Screen

entity-service-decorator.test.js

Source: entity-service-decorator.test.js Github

copy
1'use strict';
2
3jest.mock('../localizations', () => {
4  return () => ({
5    syncLocalizations: jest.fn(async () => {}),
6    syncNonLocalizedAttributes: jest.fn(async () => {}),
7  });
8});
9
10const { decorator } = require('../entity-service-decorator')();
11const localizations = require('../localizations')();
12const locales = require('../locales')();
13const contentTypes = require('../content-types')();
14
15const { syncLocalizations, syncNonLocalizedAttributes } = localizations;
16
17const model = {
18  pluginOptions: {
19    i18n: {
20      localized: true,
21    },
22  },
23};
24
25const nonLocalizedModel = {
26  pluginOptions: {
27    i18n: {
28      localized: false,
29    },
30  },
31};
32
33const models = {
34  'test-model': model,
35  'non-localized-model': nonLocalizedModel,
36};
37
38describe('Entity service decorator', () => {
39  beforeAll(() => {
40    global.strapi = {
41      plugins: {
42        i18n: {
43          services: {
44            locales,
45            'content-types': contentTypes,
46            localizations,
47          },
48        },
49      },
50      query() {
51        return {
52          create() {},
53          update() {},
54        };
55      },
56      getModel(uid) {
57        return models[uid || 'test-model'];
58      },
59      store: () => ({ get: () => 'en' }),
60    };
61  });
62
63  beforeEach(() => {
64    syncLocalizations.mockClear();
65    syncNonLocalizedAttributes.mockClear();
66  });
67
68  describe('wrapParams', () => {
69    test('Calls original wrapParams', async () => {
70      const defaultService = {
71        wrapParams: jest.fn(() => Promise.resolve('li')),
72      };
73
74      const service = decorator(defaultService);
75
76      const input = { populate: ['test'] };
77      await service.wrapParams(input, { uid: 'test-model' });
78
79      expect(defaultService.wrapParams).toHaveBeenCalledWith(input, { uid: 'test-model' });
80    });
81
82    test('Does not wrap options if model is not localized', async () => {
83      const defaultService = {
84        wrapParams: jest.fn(opts => Promise.resolve(opts)),
85      };
86      const service = decorator(defaultService);
87
88      const input = { populate: ['test'] };
89      const output = await service.wrapParams(input, { uid: 'non-localized-model' });
90
91      expect(output).toStrictEqual(input);
92    });
93
94    test('does not change non params options', async () => {
95      const defaultService = {
96        wrapParams: jest.fn(opts => Promise.resolve(opts)),
97      };
98      const service = decorator(defaultService);
99
100      const input = { populate: ['test'] };
101      const output = await service.wrapParams(input, { uid: 'test-model' });
102
103      expect(output.populate).toStrictEqual(input.populate);
104    });
105
106    test('Adds locale param', async () => {
107      const defaultService = {
108        wrapParams: jest.fn(opts => Promise.resolve(opts)),
109      };
110      const service = decorator(defaultService);
111
112      const input = { populate: ['test'] };
113      const output = await service.wrapParams(input, { uid: 'test-model' });
114
115      expect(output).toMatchObject({ filters: { $and: [{ locale: 'en' }] } });
116    });
117
118    const testData = [
119      ['findOne', { filters: { id: 1 } }],
120      ['update', { filters: { id: 1 } }],
121      ['delete', { filters: { id: 1 } }],
122      ['delete', { filters: { id: { $in: [1] } } }],
123      ['findOne', { filters: [{ id: 1 }] }],
124      ['update', { filters: [{ id: 1 }] }],
125      ['delete', { filters: [{ id: 1 }] }],
126      ['delete', { filters: [{ id: { $in: [1] } }] }],
127    ];
128
129    test.each(testData)(
130      "Doesn't add locale param when the params contain id or id_in - %s",
131      async (action, params) => {
132        const defaultService = {
133          wrapParams: jest.fn(opts => Promise.resolve(opts)),
134        };
135        const service = decorator(defaultService);
136
137        const input = Object.assign({ populate: ['test'], ...params });
138        const output = await service.wrapParams(input, { uid: 'test-model', action });
139
140        expect(output).toEqual({ populate: ['test'], ...params });
141      }
142    );
143
144    test('Replaces locale param', async () => {
145      const defaultService = {
146        wrapParams: jest.fn(opts => Promise.resolve(opts)),
147      };
148      const service = decorator(defaultService);
149
150      const input = {
151        locale: 'fr',
152        populate: ['test'],
153      };
154      const output = await service.wrapParams(input, { uid: 'test-model' });
155
156      expect(output).toMatchObject({ filters: { $and: [{ locale: 'fr' }] } });
157    });
158  });
159
160  describe('create', () => {
161    test('Calls original create', async () => {
162      const entry = {
163        id: 1,
164      };
165
166      const defaultService = {
167        create: jest.fn(() => Promise.resolve(entry)),
168      };
169
170      const service = decorator(defaultService);
171
172      const input = { data: { title: 'title ' } };
173      await service.create('test-model', input);
174
175      expect(defaultService.create).toHaveBeenCalledWith('test-model', input);
176    });
177
178    test('Calls syncLocalizations if model is localized', async () => {
179      const entry = {
180        id: 1,
181        localizations: [{ id: 2 }],
182      };
183
184      const defaultService = {
185        create: jest.fn(() => Promise.resolve(entry)),
186      };
187
188      const service = decorator(defaultService);
189
190      const input = { data: { title: 'title ' } };
191      await service.create('test-model', input);
192
193      expect(defaultService.create).toHaveBeenCalledWith('test-model', input);
194      expect(syncLocalizations).toHaveBeenCalledWith(entry, { model });
195    });
196
197    test('Skip processing if model is not localized', async () => {
198      const entry = {
199        id: 1,
200        localizations: [{ id: 2 }],
201      };
202
203      const defaultService = {
204        create: jest.fn(() => Promise.resolve(entry)),
205      };
206
207      const service = decorator(defaultService);
208
209      const input = { data: { title: 'title ' } };
210      const output = await service.create('non-localized-model', input);
211
212      expect(defaultService.create).toHaveBeenCalledWith('non-localized-model', input);
213      expect(syncLocalizations).not.toHaveBeenCalled();
214      expect(output).toStrictEqual(entry);
215    });
216  });
217
218  describe('update', () => {
219    test('Calls original update', async () => {
220      const entry = {
221        id: 1,
222      };
223
224      const defaultService = {
225        update: jest.fn(() => Promise.resolve(entry)),
226      };
227
228      const service = decorator(defaultService);
229
230      const input = { data: { title: 'title ' } };
231      await service.update('test-model', 1, input);
232
233      expect(defaultService.update).toHaveBeenCalledWith('test-model', 1, input);
234    });
235
236    test('Calls syncNonLocalizedAttributes if model is localized', async () => {
237      const entry = {
238        id: 1,
239        localizations: [{ id: 2 }],
240      };
241
242      const defaultService = {
243        update: jest.fn(() => Promise.resolve(entry)),
244      };
245
246      const service = decorator(defaultService);
247
248      const input = { data: { title: 'title ' } };
249      const output = await service.update('test-model', 1, input);
250
251      expect(defaultService.update).toHaveBeenCalledWith('test-model', 1, input);
252      expect(syncNonLocalizedAttributes).toHaveBeenCalledWith(entry, { model });
253      expect(output).toStrictEqual(entry);
254    });
255
256    test('Skip processing if model is not localized', async () => {
257      const entry = {
258        id: 1,
259        localizations: [{ id: 2 }],
260      };
261
262      const defaultService = {
263        update: jest.fn(() => Promise.resolve(entry)),
264      };
265
266      const service = decorator(defaultService);
267
268      const input = { data: { title: 'title ' } };
269      await service.update('non-localized-model', 1, input);
270
271      expect(defaultService.update).toHaveBeenCalledWith('non-localized-model', 1, input);
272      expect(syncNonLocalizedAttributes).not.toHaveBeenCalled();
273    });
274  });
275});
276
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Base Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)