From 71cebb2267a64e79e3b07eb61ad6416a7b817fc0 Mon Sep 17 00:00:00 2001 From: Patrick Tolosa <patrick.tolosa@cloudinary.com> Date: Tue, 10 Mar 2020 11:24:21 +0200 Subject: [PATCH 1/5] Refactor out a duplicate test This test was a duplicate of line 65 in the same file: 'Accepts credentials as an argument' --- test/provisioning/account_spec.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/provisioning/account_spec.js b/test/provisioning/account_spec.js index c640e660..b13832ef 100644 --- a/test/provisioning/account_spec.js +++ b/test/provisioning/account_spec.js @@ -62,18 +62,6 @@ describe('account API - Provisioning', function () { expect(delGroupRes.ok).to.eql(true); // notice the different response structure }); - it('Accepts auth when a new instance of cloudinary is created', async () => { - let NEW_NAME = 'This wont be created'; - let options = { - provisioning_api_key: 'abc', - provisioning_api_secret: 'abc', - }; - - await cloudinary.provisioning.account.create_sub_account(CLOUD_ID, NEW_NAME, {}, null, null, options).catch((errRes) => { - expect(errRes.error.http_code).to.eql(401); - }); - }); - it('Accepts credentials as an argument', async () => { let NEW_NAME = 'This wont be created'; let options = { From 01430b98ea1a7f41410167ec4998c874d934df58 Mon Sep 17 00:00:00 2001 From: Patrick Tolosa <patrick.tolosa@cloudinary.com> Date: Tue, 10 Mar 2020 11:36:46 +0200 Subject: [PATCH 2/5] improve provisioning api tests for GET sub_accounts - Add a test for prefix - Add a test for ids[] in the API --- test/provisioning/account_spec.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/provisioning/account_spec.js b/test/provisioning/account_spec.js index b13832ef..e845a4ab 100644 --- a/test/provisioning/account_spec.js +++ b/test/provisioning/account_spec.js @@ -16,6 +16,7 @@ describe('account API - Provisioning', function () { let USER_ROLE = 'billing'; let USER_ID; let GROUP_ID; + let CLOUD_NAME_PREFIX = 'justaname'; this.timeout(helper.TIMEOUT_LONG); before("Setup the required test", async function () { @@ -25,13 +26,13 @@ describe('account API - Provisioning', function () { } // Create a sub account(sub cloud) - let res = await cloudinary.provisioning.account.create_sub_account('jutaname' + Date.now(), 'jutaname' + Date.now(), {}, true).catch((err) => { + let res = await cloudinary.provisioning.account.create_sub_account(CLOUD_NAME_PREFIX + Date.now(), CLOUD_NAME_PREFIX + Date.now(), {}, true).catch((err) => { throw err; }); CLOUD_API = res.api_access_keys[0].key; CLOUD_SECRET = res.api_access_keys[0].secret; - CLOUD_NAME = res.api_access_keys.cloud_name; + CLOUD_NAME = res.cloud_name; CLOUD_ID = res.id; let createUser = await cloudinary.provisioning.account.create_user(USER_NAME, USER_EMAIL, USER_ROLE, []).catch((err) => { @@ -95,6 +96,22 @@ describe('account API - Provisioning', function () { }); }); + it('Get a specific subAccount', async function () { + return cloudinary.provisioning.account.sub_accounts(true, [CLOUD_ID]).then((res) => { + expect(res.sub_accounts.length).to.eql(1); + }).catch((err) => { + throw err; + }); + }); + + it('Get sub-accounts by prefix', async function () { + return cloudinary.provisioning.account.sub_accounts(true, [], CLOUD_NAME_PREFIX).then((res) => { + expect(res.sub_accounts.length).to.eql(1); + }).catch((err) => { + throw err; + }); + }); + it('Gets a specific subAccount', async function () { return cloudinary.provisioning.account.sub_account(CLOUD_ID).then((res) => { expect(res.id).to.eql(CLOUD_ID); From 40c1c98ee2bd70c10a6e97c6d88ce8c5739588a5 Mon Sep 17 00:00:00 2001 From: Patrick Tolosa <patrick.tolosa@cloudinary.com> Date: Tue, 10 Mar 2020 12:33:42 +0200 Subject: [PATCH 3/5] Fix prefix name in update sub account --- test/provisioning/account_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/provisioning/account_spec.js b/test/provisioning/account_spec.js index bc35b395..9a2c065b 100644 --- a/test/provisioning/account_spec.js +++ b/test/provisioning/account_spec.js @@ -74,7 +74,7 @@ describe('account API - Provisioning', function () { }); it('Updates a sub account', async () => { - let NEW_NAME = 'new-test-name'; + let NEW_NAME = CLOUD_NAME_PREFIX + Date.now(); await cloudinary.provisioning.account.update_sub_account(CLOUD_ID, NEW_NAME); let subAccRes = await cloudinary.provisioning.account.sub_account(CLOUD_ID); From 0094a4f188ac0c99d723ed1afc8147e7872260da Mon Sep 17 00:00:00 2001 From: Patrick Tolosa <patrick.tolosa@cloudinary.com> Date: Wed, 11 Mar 2020 10:21:24 +0200 Subject: [PATCH 4/5] improve the atomic-ness of the provisioning test --- test/provisioning/account_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/provisioning/account_spec.js b/test/provisioning/account_spec.js index 9a2c065b..8a215b19 100644 --- a/test/provisioning/account_spec.js +++ b/test/provisioning/account_spec.js @@ -16,7 +16,7 @@ describe('account API - Provisioning', function () { let USER_ROLE = 'billing'; let USER_ID; let GROUP_ID; - let CLOUD_NAME_PREFIX = 'justaname'; + let CLOUD_NAME_PREFIX = `justaname${process.hrtime()[1] % 10000}`; this.timeout(helper.TIMEOUT_LONG); before("Setup the required test", async function () { From 82ea8378bc875e69201e57264182fc3eaa300a74 Mon Sep 17 00:00:00 2001 From: Patrick Tolosa <patrick.tolosa@cloudinary.com> Date: Thu, 12 Mar 2020 09:22:03 +0200 Subject: [PATCH 5/5] refactor test file - extract cloud_name and name to a variable --- test/provisioning/account_spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/provisioning/account_spec.js b/test/provisioning/account_spec.js index 8a215b19..9c09b83a 100644 --- a/test/provisioning/account_spec.js +++ b/test/provisioning/account_spec.js @@ -25,8 +25,9 @@ describe('account API - Provisioning', function () { expect().fail("Missing key and secret. Please set CLOUDINARY_ACCOUNT_URL."); } + let CLOUD_TO_CREATE = CLOUD_NAME_PREFIX + Date.now(); // Create a sub account(sub cloud) - let res = await cloudinary.provisioning.account.create_sub_account(CLOUD_NAME_PREFIX + Date.now(), CLOUD_NAME_PREFIX + Date.now(), {}, true).catch((err) => { + let res = await cloudinary.provisioning.account.create_sub_account(CLOUD_TO_CREATE, CLOUD_TO_CREATE, {}, true).catch((err) => { throw err; });