• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 mockDistributedAccount() {
19  const distributedInfoMock = {
20    name: "[PC Preview] unknown name",
21    id: "[PC Preview] unknown id",
22    event: "[PC Preview] unknown event",
23    scalableData: "[PC Preview] unknown scalableData"
24  }
25  const distributedAccountAbilityMock = {
26    queryOsAccountDistributedInfo: function (...args) {
27      console.warn("DistributedAccountAbility.queryOsAccountDistributedInfo interface mocked in the Previewer." +
28        " How this interface works on the Previewer may be different from that on a real device.")
29      const len = args.length
30      if (len > 0 && typeof args[len - 1] === 'function') {
31        args[len - 1].call(this, paramMock.businessErrorMock, distributedInfoMock);
32      } else {
33        return new Promise((resolve, reject) => {
34          resolve(distributedInfoMock);
35        })
36      }
37    },
38    updateOsAccountDistributedInfo: function (...args) {
39      console.warn("DistributedAccountAbility.updateOsAccountDistributedInfo interface mocked in the Previewer." +
40        " How this interface works on the Previewer may be different from that on a real device.")
41      const len = args.length
42      if (len > 0 && typeof args[len - 1] === 'function') {
43        args[len - 1].call(this, paramMock.businessErrorMock);
44      } else {
45        return new Promise((resolve, reject) => {
46          resolve();
47        })
48      }
49    }
50  };
51  const distributedAccount = {
52    getDistributedAccountAbility: function (...args) {
53      console.warn("distributedAccount.getDistributedAccountAbility interface mocked in the Previewer." +
54        " How this interface works on the Previewer may be different from that on a real device.")
55      return distributedAccountAbilityMock;
56    }
57  }
58  return distributedAccount;
59}