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 */ 15import account from '@ohos.account.appAccount' 16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 17 18const TIMEOUT = 5000; 19describe('ActsCreatAppAccountManager', function () { 20 function sleep(delay) { 21 return new Promise((resolve, reject) => { 22 setTimeout(() => { 23 resolve() 24 }, delay) 25 }).then(() => { 26 console.info(`sleep #{time} over ...`) 27 }) 28 } 29 30 beforeAll(async function (done) { 31 console.debug("====>beforeAll start===="); 32 await sleep(TIMEOUT); 33 console.debug("====>beforeAll end===="); 34 done(); 35 }); 36 37 /* 38 * @tc.number : ActsCreatAppAccountManager_0100 39 * @tc.name : createAppAccountManager 40 * @tc.desc : Create two application account module objects, one object adds an application account, 41 * the other object deletes the application account 42 */ 43 it('ActsCreatAppAccountManager_0100', 0, async function (done) { 44 console.debug("====>ActsCreatAppAccountManager_0100 start===="); 45 var appAccountManager = account.createAppAccountManager(); 46 var appAccountManagerTwo = account.createAppAccountManager(); 47 console.debug("====>creat finish===="); 48 appAccountManager.addAccount("creatappaccount_name_first", (err)=>{ 49 console.debug("====>add account ActsCreatAppAccountManager_0100 err:" + JSON.stringify(err)); 50 expect(err).assertEqual(null); 51 appAccountManagerTwo.deleteAccount("creatappaccount_name_first", (err)=>{ 52 console.debug("====>delete Account ActsCreatAppAccountManager_0100 err:" + JSON.stringify(err)); 53 expect(err).assertEqual(null); 54 console.debug("====>ActsCreatAppAccountManager_0100 end===="); 55 done(); 56 }); 57 }); 58 }); 59 60 /* 61 * @tc.number : ActsCreatAppAccountManager_0200 62 * @tc.name : createAppAccountManager 63 * @tc.desc : Create two application account module objects, one object adds application accounts and 64 * sets additional information, and the other object can obtain additional information of 65 * the application account 66 */ 67 it('ActsCreatAppAccountManager_0200', 0, async function (done) { 68 console.debug("====>ActsCreatAppAccountManager_0200 start===="); 69 var appAccountManager = account.createAppAccountManager(); 70 var appAccountManagerTwo = account.createAppAccountManager(); 71 console.debug("====>creat finish===="); 72 appAccountManager.addAccount("creatappaccount_name_second", (err)=>{ 73 console.debug("====>add account ActsCreatAppAccountManager_0200 err:" + JSON.stringify(err)); 74 expect(err).assertEqual(null); 75 appAccountManagerTwo.setAccountExtraInfo("creatappaccount_name_second", "creatappaccount_extra", (err)=>{ 76 console.debug("====>setAccountExtraInfo err:" + JSON.stringify(err)); 77 expect(err).assertEqual(null); 78 appAccountManager.getAccountExtraInfo("creatappaccount_name_second", (err, data)=>{ 79 console.debug("====>getAccountExtraInfo err:" + JSON.stringify(err)); 80 console.debug("====>getAccountExtraInfo data:" + JSON.stringify(data)); 81 expect(err).assertEqual(null); 82 expect(data).assertEqual("creatappaccount_extra"); 83 appAccountManagerTwo.deleteAccount("creatappaccount_name_second", (err)=>{ 84 console.debug("====>delete Account err:" + JSON.stringify(err)); 85 expect(err).assertEqual(null); 86 console.debug("====>ActsCreatAppAccountManager_0200 end===="); 87 done(); 88 }); 89 }); 90 }); 91 }); 92 }); 93})