From 864db844f082ec4c448c9104e6de2b4434010b07 Mon Sep 17 00:00:00 2001 From: harshithad0703 Date: Tue, 7 Nov 2023 09:44:02 +0530 Subject: [PATCH] added assertions to check the response --- test/api/team-stack-role-mapping-test.js | 85 +++++++++++------------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/test/api/team-stack-role-mapping-test.js b/test/api/team-stack-role-mapping-test.js index e52597bf..092b31eb 100644 --- a/test/api/team-stack-role-mapping-test.js +++ b/test/api/team-stack-role-mapping-test.js @@ -14,60 +14,55 @@ describe('Teams API Test', () => { const user = jsonReader('loggedinuser.json') client = contentstackClient(user.authtoken) }) - it('should fetch all stackRoleMappings', async () => { - try { - makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => { - console.log('🚀 ~ file: team-stack-role-mapping-test.js:19 ~ makestackRoleMappings ~ response:', response.stackRoleMappings[0].roles) + it('should fetch all stackRoleMappings', done => { + makestackRoleMappings(organizationUid, teamUid).fetchAll().then((response) => { + response.items.forEach((stackRoleMapping) => { + console.log(stackRoleMapping) }) - } catch (err) { - console.log("🚀 ~ file: team-stack-role-mapping-test.js:21 ~ it.only ~ err:", err) - } + expect(response).to.be.not.equal(null) + done() + }) + .catch(done) }) - it('should add roles', async () => { - try { - const stackRoleMappings = { - stackApiKey: 'stackApiKey', - roles: [ - 'role_uid' - ] - } - await makestackRoleMappings(organizationUid, teamUid).add(stackRoleMappings).then((response) => { - console.log('🚀 ~ file: team-stack-role-mapping-test.js:36 ~ awaitmakestackRoleMappings ~ response:', response) - }) - } catch (err) { - console.log(err) + it('should add roles', done => { + const stackRoleMappings = { + stackApiKey: 'stackApiKey', + roles: [ + 'role_uid' + ] } + makestackRoleMappings(organizationUid, teamUid).add(stackRoleMappings).then((response) => { + expect(response.stackRoleMapping).not.to.be.equal(undefined) + expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0]) + expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackRoleMappings.stackApiKey) + done() + }) + .catch(done) }) - it('should update roles', async () => { - try { - const stackRoleMappings = { - roles: [ - 'role_uid1', - 'role_uid2' - ] - } - await makestackRoleMappings(organizationUid, teamUid, stackApiKey).update(stackRoleMappings).then((response) => { - console.log('🚀 ~ file: team-stack-role-mapping-test.js:31 ~ makestackRoleMappings ~ response:', response) - }) - } catch (err) { - console.log(err.errors) + it('should update roles', done => { + const stackRoleMappings = { + roles: [ + 'role_uid1', + 'role_uid2' + ] } + makestackRoleMappings(organizationUid, teamUid, stackApiKey).update(stackRoleMappings).then((response) => { + expect(response.stackRoleMapping).not.to.be.equal(undefined) + expect(response.stackRoleMapping.roles[0]).to.be.equal(stackRoleMappings.roles[0]) + expect(response.stackRoleMapping.stackApiKey).to.be.equal(stackApiKey) + done() + }) + .catch(done) }) - it('should delete roles', async () => { - try { - await makestackRoleMappings(organizationUid, teamUid, stackApiKey).delete().then((response) => { - console.log('🚀 ~ file: team-stack-role-mapping-test.js:31 ~ makestackRoleMappings ~ response:', response) - }) - } catch (err) { - console.log(err.errors) - } + it('should delete roles', done => { + makestackRoleMappings(organizationUid, teamUid, stackApiKey).delete().then((response) => { + expect(response.status).to.be.equal(204) + done() + }) + .catch(done) }) }) function makestackRoleMappings (organizationUid, teamUid, stackApiKey = null) { return client.organization(organizationUid).teams(teamUid).stackRoleMappings(stackApiKey) } - -// delete done -// update done -// add done