• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { paramMock } from "../utils"
17
18export function mockAppAccount() {
19  const appAccountInfoMock = {
20    owner: "[PC Preview] unknown owner",
21    name: "[PC Preview] unknown name"
22  };
23  const OAuthTokenInfoMock = {
24    authType: "[PC preview] unknown authType",
25    token: "[PC preview] unknown token"
26  };
27  const AuthenticatorInfoMock = {
28    owner: "[PC preview] unknown owner",
29    iconId: "[PC preview] unknown iconId",
30    labelId: "[PC preview] unknown labelId",
31  };
32
33  const appAccountManagerMock = {
34    addAccount: function (...args) {
35      console.warn("AppAccountManager.addAccount interface mocked in the Previewer. " +
36        "How this interface works on the Previewer may be different from that on a real device.")
37      const len = args.length
38      if (len > 0 && typeof args[len - 1] === 'function') {
39        args[len - 1].call(this, paramMock.businessErrorMock);
40      } else {
41        return new Promise((resolve, reject) => {
42          resolve();
43        })
44      }
45    },
46    addAccountImplicitly: function (...args) {
47      console.warn("AppAccountManager.addAccountImplicitly interface mocked in the Previewer. " +
48        "How this interface works on the Previewer may be different from that on a real device.")
49      const len = args.length
50      if (len > 0 && typeof args[len - 1] === 'function') {
51        args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock);
52      }
53    },
54    deleteAccount: function (...args) {
55      console.warn("AppAccountManager.deleteAccount interface mocked in the Previewer. " +
56        "How this interface works on the Previewer may be different from that on a real device.")
57      const len = args.length
58      if (len > 0 && typeof args[len - 1] === 'function') {
59        args[len - 1].call(this, paramMock.businessErrorMock);
60      } else {
61        return new Promise((resolve, reject) => {
62          resolve();
63        })
64      }
65    },
66    disableAppAccess: function (...args) {
67      console.warn("AppAccountManager.disableAppAccess interface mocked in the Previewer. " +
68        "How this interface works on the Previewer may be different from that on a real device.")
69      const len = args.length
70      if (len > 0 && typeof args[len - 1] === 'function') {
71        args[len - 1].call(this, paramMock.businessErrorMock);
72      } else {
73        return new Promise((resolve, reject) => {
74          resolve();
75        })
76      }
77    },
78    enableAppAccess: function (...args) {
79      console.warn("AppAccountManager.enableAppAccess interface mocked in the Previewer. " +
80        "How this interface works on the Previewer may be different from that on a real device.")
81      const len = args.length
82      if (len > 0 && typeof args[len - 1] === 'function') {
83        args[len - 1].call(this, paramMock.businessErrorMock);
84      } else {
85        return new Promise((resolve, reject) => {
86          resolve();
87        })
88      }
89    },
90    checkAppAccountSyncEnable: function (...args) {
91      console.warn("AppAccountManager.checkAppAccountSyncEnable interface mocked in the Previewer. " +
92        "How this interface works on the Previewer may be different from that on a real device.")
93      const len = args.length
94      if (len > 0 && typeof args[len - 1] === 'function') {
95        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
96      } else {
97        return new Promise((resolve, reject) => {
98          resolve(paramMock.paramBooleanMock);
99        })
100      }
101    },
102    setAccountCredential: function (...args) {
103      console.warn("AppAccountManager.setAccountCredential interface mocked in the Previewer. " +
104        "How this interface works on the Previewer may be different from that on a real device.")
105      const len = args.length
106      if (len > 0 && typeof args[len - 1] === 'function') {
107        args[len - 1].call(this, paramMock.businessErrorMock);
108      } else {
109        return new Promise((resolve, reject) => {
110          resolve();
111        })
112      }
113    },
114    setAccountExtraInfo: function (...args) {
115      console.warn("AppAccountManager.setAccountExtraInfo interface mocked in the Previewer. " +
116        "How this interface works on the Previewer may be different from that on a real device.")
117      const len = args.length
118      if (len > 0 && typeof args[len - 1] === 'function') {
119        args[len - 1].call(this, paramMock.businessErrorMock);
120      } else {
121        return new Promise((resolve, reject) => {
122          resolve();
123        })
124      }
125    },
126    setAppAccountSyncEnable: function (...args) {
127      console.warn("AppAccountManager.setAppAccountSyncEnable interface mocked in the Previewer. " +
128        "How this interface works on the Previewer may be different from that on a real device.")
129      const len = args.length
130      if (len > 0 && typeof args[len - 1] === 'function') {
131        args[len - 1].call(this, paramMock.businessErrorMock);
132      } else {
133        return new Promise((resolve, reject) => {
134          resolve();
135        })
136      }
137    },
138    setAssociatedData: function (...args) {
139      console.warn("AppAccountManager.setAssociatedData interface mocked in the Previewer. " +
140        "How this interface works on the Previewer may be different from that on a real device.")
141      const len = args.length
142      if (len > 0 && typeof args[len - 1] === 'function') {
143        args[len - 1].call(this, paramMock.businessErrorMock);
144      } else {
145        return new Promise((resolve, reject) => {
146          resolve();
147        })
148      }
149    },
150    getAllAccessibleAccounts: function (...args) {
151      console.warn("AppAccountManager.getAllAccessibleAccounts interface mocked in the Previewer. " +
152        "How this interface works on the Previewer may be different from that on a real device.")
153      var appAccountInfoArrayMock = new Array();
154      appAccountInfoArrayMock.push(appAccountInfoMock);
155      const len = args.length
156      if (len > 0 && typeof args[len - 1] === 'function') {
157        args[len - 1].call(this, paramMock.businessErrorMock, appAccountInfoArrayMock);
158      } else {
159        return new Promise((resolve, reject) => {
160          resolve(appAccountInfoArrayMock);
161        })
162      }
163    },
164    getAllAccounts: function (...args) {
165      console.warn("AppAccountManager.getAllAccounts interface mocked in the Previewer. " +
166        "How this interface works on the Previewer may be different from that on a real device.")
167      var appAccountInfoArrayMock = new Array();
168      appAccountInfoArrayMock.push(appAccountInfoMock);
169      const len = args.length
170      if (len > 0 && typeof args[len - 1] === 'function') {
171        args[len - 1].call(this, paramMock.businessErrorMock, appAccountInfoArrayMock);
172      } else {
173        return new Promise((resolve, reject) => {
174          resolve(appAccountInfoArrayMock);
175        })
176      }
177    },
178    getAccountCredential: function (...args) {
179      console.warn("AppAccountManager.getAccountCredential interface mocked in the Previewer. " +
180        "How this interface works on the Previewer may be different from that on a real device.")
181      const len = args.length
182      if (len > 0 && typeof args[len - 1] === 'function') {
183        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
184      } else {
185        return new Promise((resolve, reject) => {
186          resolve(paramMock.paramStringMock);
187        })
188      }
189    },
190    getAccountExtraInfo: function (...args) {
191      console.warn("AppAccountManager.getAccountExtraInfo interface mocked in the Previewer. " +
192        "How this interface works on the Previewer may be different from that on a real device.")
193      const len = args.length
194      if (len > 0 && typeof args[len - 1] === 'function') {
195        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
196      } else {
197        return new Promise((resolve, reject) => {
198          resolve(paramMock.paramStringMock);
199        })
200      }
201    },
202    getAssociatedData: function (...args) {
203      console.warn("AppAccountManager.getAssociatedData interface mocked in the Previewer. " +
204        "How this interface works on the Previewer may be different from that on a real device.")
205      const len = args.length
206      if (len > 0 && typeof args[len - 1] === 'function') {
207        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
208      } else {
209        return new Promise((resolve, reject) => {
210          resolve(paramMock.paramStringMock);
211        })
212      }
213    },
214    on: function (...args) {
215      console.warn("AppAccountManager.on interface mocked in the Previewer. " +
216        "How this interface works on the Previewer may be different from that on a real device.")
217      var appAccountInfoArrayMock = new Array();
218      appAccountInfoArrayMock.push(appAccountInfoMock);
219      const len = args.length
220      if (len > 0 && typeof args[len - 1] === 'function') {
221        args[len - 1].call(this, appAccountInfoArrayMock);
222      } else {
223        return new Promise((resolve, reject) => {
224          resolve(appAccountInfoArrayMock);
225        })
226      }
227    },
228    off: function (...args) {
229      console.warn("AppAccountManager.off interface mocked in the Previewer. " +
230        "How this interface works on the Previewer may be different from that on a real device.")
231      var appAccountInfoArrayMock = new Array();
232      appAccountInfoArrayMock.push(appAccountInfoMock);
233      const len = args.length
234      if (len > 0 && typeof args[len - 1] === 'function') {
235        args[len - 1].call(this, appAccountInfoArrayMock);
236      } else {
237        return new Promise((resolve, reject) => {
238          resolve(appAccountInfoArrayMock);
239        })
240      }
241    },
242    authenticate: function (...args) {
243      console.warn("AppAccountManager.authenticate interface mocked in the Previewer. " +
244        "How this interface works on the Previewer may be different from that on a real device.")
245      const len = args.length
246      if (len > 0 && typeof args[len - 1] === 'function') {
247        args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock);
248      }
249    },
250    getOAuthToken: function (...args) {
251      console.warn("AppAccountManager.getOAuthToken interface mocked in the Previewer. " +
252        "How this interface works on the Previewer may be different from that on a real device.")
253      const len = args.length
254      if (len > 0 && typeof args[len - 1] === 'function') {
255        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
256      } else {
257        return new Promise((resolve, reject) => {
258          resolve(paramMock.paramStringMock)
259        })
260      }
261    },
262    setOAuthToken: function (...args) {
263      console.warn("AppAccountManager.setOAuthToken interface mocked in the Previewer. " +
264        "How this interface works on the Previewer may be different from that on a real device.")
265      const len = args.length
266      if (len > 0 && typeof args[len - 1] === 'function') {
267        args[len - 1].call(this, paramMock.businessErrorMock);
268      } else {
269        return new Promise((resolve, reject) => {
270          resolve()
271        })
272      }
273    },
274    deleteOAuthToken: function (...args) {
275      console.warn("AppAccountManager.deleteOAuthToken interface mocked in the Previewer. " +
276        "How this interface works on the Previewer may be different from that on a real device.")
277      const len = args.length
278      if (len > 0 && typeof args[len - 1] === 'function') {
279        args[len - 1].call(this, paramMock.businessErrorMock);
280      } else {
281        return new Promise((resolve, reject) => {
282          resolve()
283        })
284      }
285    },
286    setOAuthTokenVisibility: function (...args) {
287      console.warn("AppAccountManager.setOAuthTokenVisibility interface mocked in the Previewer. " +
288        "How this interface works on the Previewer may be different from that on a real device.")
289      const len = args.length
290      if (len > 0 && typeof args[len - 1] === 'function') {
291        args[len - 1].call(this, paramMock.businessErrorMock);
292      } else {
293        return new Promise((resolve, reject) => {
294          resolve()
295        })
296      }
297    },
298    checkOAuthTokenVisibility: function (...args) {
299      console.warn("AppAccountManager.checkOAuthTokenVisibility interface mocked in the Previewer. " +
300        "How this interface works on the Previewer may be different from that on a real device.")
301      const len = args.length
302      if (len > 0 && typeof args[len - 1] === 'function') {
303        args[len - 1].call(this, paramMock.businessErrorMock);
304      } else {
305        return new Promise((resolve, reject) => {
306          resolve()
307        })
308      }
309    },
310    getAllOAuthTokens: function (...args) {
311      console.warn("AppAccountManager.getAllOAuthTokens interface mocked in the Previewer. " +
312        "How this interface works on the Previewer may be different from that on a real device.")
313      const len = args.length
314      if (len > 0 && typeof args[len - 1] === 'function') {
315        args[len - 1].call(this, paramMock.businessErrorMock, new Array(OAuthTokenInfoMock));
316      } else {
317        return new Promise((resolve, reject) => {
318          resolve(new Array(OAuthTokenInfoMock))
319        })
320      }
321    },
322    getOAuthList: function (...args) {
323      console.warn("AppAccountManager.getOAuthList interface mocked in the Previewer. " +
324        "How this interface works on the Previewer may be different from that on a real device.")
325      const len = args.length
326      if (len > 0 && typeof args[len - 1] === 'function') {
327        args[len - 1].call(this, paramMock.businessErrorMock, new Array(paramMock.paramStringMock));
328      } else {
329        return new Promise((resolve, reject) => {
330          resolve(new Array(paramMock.paramStringMock))
331        })
332      }
333    },
334    getAuthenticatorCallback: function (...args) {
335      console.warn("AppAccountManager.getAuthenticatorCallback interface mocked in the Previewer. " +
336        "How this interface works on the Previewer may be different from that on a real device.")
337      const len = args.length
338      if (len > 0 && typeof args[len - 1] === 'function') {
339        args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock);
340      } else {
341        return new Promise((resolve, reject) => {
342          resolve(AuthenticatorCallbackMock)
343        })
344      }
345    },
346    getAuthenticatorInfo: function (...args) {
347      console.warn("AppAccountManager.getAuthenticatorInfo interface mocked in the Previewer. " +
348        "How this interface works on the Previewer may be different from that on a real device.")
349      const len = args.length
350      if (len > 0 && typeof args[len - 1] === 'function') {
351        args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorInfoMock);
352      } else {
353        return new Promise((resolve, reject) => {
354          resolve(AuthenticatorInfoMock)
355        })
356      }
357    }
358  };
359  const AuthenticatorCallbackMock = {
360    onResult: function (...args) {
361      console.warn("AuthenticatorCallback.onResult interface mocked in the Previewer. " +
362        "How this interface works on the Previewer may be different from that on a real device.")
363    },
364    onRequestRedirected: function (...args) {
365      console.warn("AuthenticatorCallback.onRequestRedirected interface mocked in the Previewer. " +
366        "How this interface works on the Previewer may be different from that on a real device.")
367    }
368  };
369  const AuthenticatorClass = class Authenticator {
370    constructor() {
371      console.warn("appAccount.Authenticator constructor interface mocked in the Previewer. " +
372        "How this interface works on the Previewer may be different from that on a real device.")
373      this.addAccountImplicitly = function (...args) {
374        console.warn("Authenticator.addAccountImplicitly interface mocked in the Previewer. " +
375          "How this interface works on the Previewer may be different from that on a real device.")
376        const len = args.length
377        if (len > 0 && typeof args[len - 1] === 'function') {
378          args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock);
379        }
380      };
381      this.authenticate = function (...args) {
382        console.warn("Authenticator.authenticate interface mocked in the Previewer. " +
383          "How this interface works on the Previewer may be different from that on a real device.")
384        const len = args.length
385        if (len > 0 && typeof args[len - 1] === 'function') {
386          args[len - 1].call(this, paramMock.businessErrorMock, AuthenticatorCallbackMock);
387        }
388      };
389    }
390  };
391  const ConstantsMock = {
392    ACTION_ADD_ACCOUNT_IMPLICITLY: '[PC preview] unknow string',
393    ACTION_AUTHENTICATE: '[PC preview] unknow string',
394    KEY_NAME: '[PC preview] unknow string',
395    KEY_OWNER: '[PC preview] unknow string',
396    KEY_TOKEN: '[PC preview] unknow string',
397    KEY_ACTION: '[PC preview] unknow string',
398    KEY_AUTH_TYPE: '[PC preview] unknow string',
399    KEY_SESSION_ID: '[PC preview] unknow string',
400    KEY_CALLER_PID: '[PC preview] unknow string',
401    KEY_CALLER_UID: '[PC preview] unknow string',
402    KEY_CALLER_BUNDLE_NAME: '[PC preview] unknow string'
403  };
404  const ResultCodeMock = {
405    SUCCESS: '[PC preview] unknow resultCode',
406    ERROR_ACCOUNT_NOT_EXIST: '[PC preview] unknow resultCode',
407    ERROR_APP_ACCOUNT_SERVICE_EXCEPTION: '[PC preview] unknow resultCode',
408    ERROR_INVALID_PASSWORD: '[PC preview] unknow resultCode',
409    ERROR_INVALID_REQUEST: '[PC preview] unknow resultCode',
410    ERROR_INVALID_RESPONSE: '[PC preview] unknow resultCode',
411    ERROR_NETWORK_EXCEPTION: '[PC preview] unknow resultCode',
412    ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST: '[PC preview] unknow resultCode',
413    ERROR_OAUTH_CANCELED: '[PC preview] unknow resultCode',
414    ERROR_OAUTH_LIST_TOO_LARGE: '[PC preview] unknow resultCode',
415    ERROR_OAUTH_SERVICE_BUSY: '[PC preview] unknow resultCode',
416    ERROR_OAUTH_SERVICE_EXCEPTION: '[PC preview] unknow resultCode',
417    ERROR_OAUTH_SESSION_NOT_EXIST: '[PC preview] unknow resultCode',
418    ERROR_OAUTH_TIMEOUT: '[PC preview] unknow resultCode',
419    ERROR_OAUTH_TOKEN_NOT_EXIST: '[PC preview] unknow resultCode',
420    ERROR_OAUTH_TOKEN_TOO_MANY: '[PC preview] unknow resultCode',
421    ERROR_OAUTH_UNSUPPORT_ACTION: '[PC preview] unknow resultCode',
422    ERROR_OAUTH_UNSUPPORT_AUTH_TYPE: '[PC preview] unknow resultCode',
423    ERROR_PERMISSION_DENIED: '[PC preview] unknow resultCode'
424  };
425  const appAccount = {
426    createAppAccountManager: function (...args) {
427      console.warn("appAccount.createAppAccountManager interface mocked in the Previewer. " +
428        "How this interface works on the Previewer may be different from that on a real device.")
429      return appAccountManagerMock;
430    },
431    AuthenticatorCallback: AuthenticatorCallbackMock,
432    Authenticator: AuthenticatorClass,
433    Constants: ConstantsMock,
434    ResultCode: ResultCodeMock,
435  }
436  return appAccount
437}