Skip to content

Commit

Permalink
Merge branch 'next' into snyk-upgrade-d6ff5dd9aa34013e8d34f694960a55b7
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 authored Feb 16, 2024
2 parents 9634594 + e70c0e4 commit 24c322e
Show file tree
Hide file tree
Showing 30 changed files with 1,525 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threshold: medium
fileignoreconfig:
- filename: package-lock.json
checksum: 2a2327aabd3f6eacf41a8e8bb3dd5afdab892683cfd15aac308f43c14108b824
checksum: 9d0340f9359927d477fe8ab4650642c068c592be63fb817651d866849e0dbbc2
version: ""
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [v1.15.3](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.3) (2024-02-16)
- Fix
- Fix for updating entry
## [v1.15.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.2) (2024-02-09)
- Fix
- Adds params support in taxonomy export method
- Adds sanity test cases
## [v1.15.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.1) (2024-01-29)
- Feature
- Taxonomy Import/Export test cases are added
Expand Down
4 changes: 2 additions & 2 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ function isAsset (data) {
}

export function cleanAssets (data) {
if (data && typeof data === "object" && Object.keys(data).length > 0) {
if (data && typeof data === "object") {
const keys = Object.keys(data);
for (const key of keys) {
if (typeof data[key] === "object" && Object.keys(data[key]).length > 0) {
if (data[key] !== null && data[key] !== undefined && typeof data[key] === "object") {
if (isAsset(data[key])) {
data[key] = (Array.isArray(data[key])) ? data[key].map(element => element.uid) : data[key].uid;
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/organization/teams/teamUsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export function TeamUsers (http, data) {
}
}
export function UsersCollection (http, data) {
const obj = cloneDeep(data.teamUsers) || []
const usersCollection = obj.map((user) => {
return new TeamUsers(http, { userId: user })
const obj = cloneDeep(data.users) || []
const usersCollection = obj.map((userId) => {
return new TeamUsers(http, { userId })
})
return usersCollection
}
9 changes: 4 additions & 5 deletions lib/stack/taxonomy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ export function Taxonomy (http, data = {}) {
* .then((taxonomy) => console.log(taxonomy))
*
*/
this.export = async () => {
this.export = async (params = {}) => {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders) }
headers: { ...cloneDeep(this.stackHeaders) },
params
}
const response = await http.get(`${this.urlPath}/export`, headers)
if (response.data) {
Expand All @@ -103,7 +104,6 @@ export function Taxonomy (http, data = {}) {
}
}


this.terms = (uid = '') => {
const data = { stackHeaders: this.stackHeaders }
data.taxonomy_uid = this.uid
Expand Down Expand Up @@ -183,7 +183,6 @@ export function Taxonomy (http, data = {}) {
throw error(err)
}
}

}
}
export function TaxonomyCollection (http, data) {
Expand All @@ -201,4 +200,4 @@ export function createFormData (data) {
formData.append('taxonomy', uploadStream)
return formData
}
}
}
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.15.1",
"version": "1.15.3",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
Expand Down
4 changes: 2 additions & 2 deletions test/api/taxonomy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ describe('taxonomy api Test', () => {
makeTaxonomy()
.import(importTaxonomy)
.then((taxonomyResponse) => {
expect(taxonomyResponse.name).to.be.equal("name")
expect(taxonomyResponse.name).to.be.equal('name')
done()
})
.catch(done)
})

it('Export taxonomy', done => {
makeTaxonomy(taxonomyUID)
.export()
.export({})
.then((taxonomyResponse) => {
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID)
expect(taxonomyResponse.name).to.be.not.equal(null)
Expand Down
146 changes: 146 additions & 0 deletions test/sanity-check/api/managementToken-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite.js'
import { createManagementToken, createManagementToken2 } from '../mock/managementToken.js'
import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}

let tokenUidProd = ''
let tokenUidDev = ''
describe('Management Token api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})

it('should add a Management Token', done => {
makeManagementToken()
.create(createManagementToken)
.then((token) => {
tokenUidDev = token.uid
expect(token.name).to.be.equal(createManagementToken.token.name)
expect(token.description).to.be.equal(createManagementToken.token.description)
expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should add a Management Token for production', done => {
makeManagementToken()
.create(createManagementToken2)
.then((token) => {
tokenUidProd = token.uid
expect(token.name).to.be.equal(createManagementToken2.token.name)
expect(token.description).to.be.equal(createManagementToken2.token.description)
expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should get a Management Token from uid', done => {
makeManagementToken(tokenUidProd)
.fetch()
.then((token) => {
expect(token.name).to.be.equal(createManagementToken2.token.name)
expect(token.description).to.be.equal(createManagementToken2.token.description)
expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should query to get all Management Token', done => {
makeManagementToken()
.query()
.find()
.then((tokens) => {
tokens.items.forEach((token) => {
expect(token.name).to.be.not.equal(null)
expect(token.description).to.be.not.equal(null)
expect(token.scope[0].module).to.be.not.equal(null)
expect(token.uid).to.be.not.equal(null)
})
done()
})
.catch(done)
})

it('should query to get a Management Token from name', done => {
makeManagementToken()
.query({ query: { name: createManagementToken.token.name } })
.find()
.then((tokens) => {
tokens.items.forEach((token) => {
expect(token.name).to.be.equal(createManagementToken.token.name)
expect(token.description).to.be.equal(createManagementToken.token.description)
expect(token.scope[0].module).to.be.equal(createManagementToken.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
})
done()
})
.catch(done)
})

it('should fetch and update a Management Token from uid', done => {
makeManagementToken(tokenUidProd)
.fetch()
.then((token) => {
token.name = 'Update Production Name'
token.description = 'Update Production description'
token.scope = createManagementToken2.token.scope
return token.update()
})
.then((token) => {
expect(token.name).to.be.equal('Update Production Name')
expect(token.description).to.be.equal('Update Production description')
expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should update a Management Token from uid', done => {
const token = makeManagementToken(tokenUidProd)
Object.assign(token, createManagementToken2.token)
token.update()
.then((token) => {
expect(token.name).to.be.equal(createManagementToken2.token.name)
expect(token.description).to.be.equal(createManagementToken2.token.description)
expect(token.scope[0].module).to.be.equal(createManagementToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('should delete a Management Token from uid', done => {
makeManagementToken(tokenUidProd)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Management Token deleted successfully.')
done()
})
.catch(done)
})

it('should delete a Management Token from uid 2', done => {
makeManagementToken(tokenUidDev)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Management Token deleted successfully.')
done()
})
.catch(done)
})
})

function makeManagementToken (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).managementToken(uid)
}
8 changes: 3 additions & 5 deletions test/sanity-check/api/organization-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { jsonReader, jsonWrite } from '../utility/fileOperations/readwrite'
import { contentstackClient } from '../utility/ContentstackClient'

var user = {}
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('Organization api test', () => {
it('should fetch organization', done => {
organization.fetch()
.then((organizations) => {
expect(organizations.name).to.be.equal('CLI Branches', 'Organization name dose not match')
expect(organizations.name).not.to.be.equal(null, 'Organization does not exist')
done()
})
.catch(done)
Expand Down Expand Up @@ -79,6 +79,7 @@ describe('Organization api test', () => {
organization.roles()
.then((roles) => {
for (const i in roles.items) {
jsonWrite(roles.items, 'orgRoles.json')
expect(roles.items[i].uid).to.not.equal(null, 'Role uid cannot be null')
expect(roles.items[i].name).to.not.equal(null, 'Role name cannot be null')
expect(roles.items[i].org_uid).to.be.equal(organization.uid, 'Role org_uid not match')
Expand All @@ -102,7 +103,4 @@ describe('Organization api test', () => {
})
.catch(done)
})

// addUser
// Resend invitation
})
Loading

0 comments on commit 24c322e

Please sign in to comment.