Skip to content

Commit 2c9cc5b

Browse files
Improve provisioning api tests (#354)
Refactor out a duplicate test improve provisioning API tests for GET sub_accounts - Add a test for prefix - Add a test for ids[] in the API Fix prefix name in "update_sub_account" test Improve the atomic-ness of the provisioning test
1 parent 1ea69c8 commit 2c9cc5b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/provisioning/account_spec.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('account API - Provisioning', function () {
1616
let USER_ROLE = 'billing';
1717
let USER_ID;
1818
let GROUP_ID;
19+
let CLOUD_NAME_PREFIX = `justaname${process.hrtime()[1] % 10000}`;
1920
this.timeout(helper.TIMEOUT_LONG);
2021

2122
before("Setup the required test", async function () {
@@ -24,14 +25,15 @@ describe('account API - Provisioning', function () {
2425
expect().fail("Missing key and secret. Please set CLOUDINARY_ACCOUNT_URL.");
2526
}
2627

28+
let CLOUD_TO_CREATE = CLOUD_NAME_PREFIX + Date.now();
2729
// Create a sub account(sub cloud)
28-
let res = await cloudinary.provisioning.account.create_sub_account('jutaname' + Date.now(), 'jutaname' + Date.now(), {}, true).catch((err) => {
30+
let res = await cloudinary.provisioning.account.create_sub_account(CLOUD_TO_CREATE, CLOUD_TO_CREATE, {}, true).catch((err) => {
2931
throw err;
3032
});
3133

3234
CLOUD_API = res.api_access_keys[0].key;
3335
CLOUD_SECRET = res.api_access_keys[0].secret;
34-
CLOUD_NAME = res.api_access_keys.cloud_name;
36+
CLOUD_NAME = res.cloud_name;
3537
CLOUD_ID = res.id;
3638

3739
let createUser = await cloudinary.provisioning.account.create_user(USER_NAME, USER_EMAIL, USER_ROLE, []).catch((err) => {
@@ -73,7 +75,7 @@ describe('account API - Provisioning', function () {
7375
});
7476

7577
it('Updates a sub account', async () => {
76-
let NEW_NAME = 'new-test-name';
78+
let NEW_NAME = CLOUD_NAME_PREFIX + Date.now();
7779
await cloudinary.provisioning.account.update_sub_account(CLOUD_ID, NEW_NAME);
7880

7981
let subAccRes = await cloudinary.provisioning.account.sub_account(CLOUD_ID);
@@ -93,6 +95,22 @@ describe('account API - Provisioning', function () {
9395
});
9496
});
9597

98+
it('Get a specific subAccount', async function () {
99+
return cloudinary.provisioning.account.sub_accounts(true, [CLOUD_ID]).then((res) => {
100+
expect(res.sub_accounts.length).to.eql(1);
101+
}).catch((err) => {
102+
throw err;
103+
});
104+
});
105+
106+
it('Get sub-accounts by prefix', async function () {
107+
return cloudinary.provisioning.account.sub_accounts(true, [], CLOUD_NAME_PREFIX).then((res) => {
108+
expect(res.sub_accounts.length).to.eql(1);
109+
}).catch((err) => {
110+
throw err;
111+
});
112+
});
113+
96114
it('Gets a specific subAccount', async function () {
97115
return cloudinary.provisioning.account.sub_account(CLOUD_ID).then((res) => {
98116
expect(res.id).to.eql(CLOUD_ID);

0 commit comments

Comments
 (0)