1/*
2 * Copyright (C) 2024 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
17
18import account from '@ohos.account.appAccount'
19
20export default function ActsAANoPermissionTest() {
21    describe('ActsAANoPermissionTest', function () {
22
23        /**
24         * @tc.number  : SUB_Account_AppAccount_NoPermission_0100
25         * @tc.name    : test checkDataSyncEnabled errcode 201 callback
26         * @tc.desc    : no ohos.permission.DISTRIBUTED_DATASYNC.
27         * @tc.level   : Level3
28         * @tc.size    : MediumTest
29         * @tc.type    : Function
30         */
31        it('SUB_Account_AppAccount_NoPermission_0100', 0, async (done) => {
32            console.info("====>SUB_Account_AppAccount_NoPermission_0100 start====");
33            let appAccountManager = account.createAppAccountManager();
34            try {
35                appAccountManager.checkDataSyncEnabled('ZhangSan', (err, isEnabled) => {
36                    console.info('====>checkDataSyncEnabled failed, err: ' + JSON.stringify(err));
37                    try {
38                        expect(err.code).assertEqual(201);
39                    } catch (err) {
40                        console.info('====>Assert err: ' + JSON.stringify(err));
41                    }
42                    done();
43                });
44            } catch (err) {
45                console.info('====>checkDataSyncEnabled err: ' + JSON.stringify(err));
46                expect(err.code).assertEqual(201);
47                done();
48            }
49        });
50
51        /**
52         * @tc.number  : SUB_Account_AppAccount_NoPermission_0200
53         * @tc.name    : test checkDataSyncEnabled errcode 201 promise
54         * @tc.desc    : no ohos.permission.DISTRIBUTED_DATASYNC.
55         * @tc.level   : Level3
56         * @tc.size    : MediumTest
57         * @tc.type    : Function
58         */
59        it('SUB_Account_AppAccount_NoPermission_0200', 0, async (done) => {
60            console.info("====>SUB_Account_AppAccount_NoPermission_0200 start====");
61            let appAccountManager = account.createAppAccountManager();
62            try {
63                await appAccountManager.checkDataSyncEnabled('ZhangSan');
64                expect(true).assertFalse()
65                done()
66            } catch (err) {
67                console.info('====>checkDataSyncEnabled err: ' + JSON.stringify(err));
68                expect(err.code).assertEqual(201);
69                done();
70            }
71        });
72
73        /**
74         * @tc.number  : SUB_Account_AppAccount_NoPermission_0300
75         * @tc.name    : test setDataSyncEnabled errcode 201 callabck
76         * @tc.desc    : no ohos.permission.DISTRIBUTED_DATASYNC.
77         * @tc.level   : Level3
78         * @tc.size    : MediumTest
79         * @tc.type    : Function
80         */
81        it('SUB_Account_AppAccount_NoPermission_0300', 0, async (done) => {
82            console.info("====>SUB_Account_AppAccount_NoPermission_0300 start====");
83            let appAccountManager = account.createAppAccountManager();
84            try {
85                appAccountManager.setDataSyncEnabled('ZhangSan', true, (err) => {
86                    console.info('====>setDataSyncEnabled err: ' + JSON.stringify(err));
87                    try {
88                        expect(err.code).assertEqual(201);
89                    } catch (err) {
90                        console.info('====>Assert err: ' + JSON.stringify(err));
91                    }
92                    done();
93                });
94            } catch (err) {
95                console.info('====>setDataSyncEnabled err: ' + JSON.stringify(err));
96                expect(err.code).assertEqual(201);
97                done();
98            }
99        });
100
101        /**
102         * @tc.number  : SUB_Account_AppAccount_NoPermission_0400
103         * @tc.name    : test setDataSyncEnabled errcode 201 promise
104         * @tc.desc    : no ohos.permission.DISTRIBUTED_DATASYNC.
105         * @tc.level   : Level3
106         * @tc.size    : MediumTest
107         * @tc.type    : Function
108         */
109        it('SUB_Account_AppAccount_NoPermission_0400', 0, async (done) => {
110            console.info("====>SUB_Account_AppAccount_NoPermission_0400 start====");
111            let appAccountManager = account.createAppAccountManager();
112            try {
113                await appAccountManager.setDataSyncEnabled('ZhangSan', true);
114                expect(true).assertFalse()
115                done()
116            } catch (err) {
117                console.info('====>checkDataSyncEnabled err: ' + JSON.stringify(err));
118                expect(err.code).assertEqual(201);
119                done();
120            }
121        });
122    });
123}