Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8516287
feat: :recycle: refactored manifest api functions in marketplace app …
nadeem-cs May 22, 2023
bd25707
refactor: :art: adds marketplace in collection and adds missing funct…
nadeem-cs May 31, 2023
ba56413
feat: :sparkles: restructures the files for marketplace apis and refa…
nadeem-cs Jun 1, 2023
e6f6cde
feat: adds webhook functions in installation and deletes previous web…
nadeem-cs Jun 5, 2023
97182f4
test: adds test cases for installation functions
nadeem-cs Jun 5, 2023
03cf2ee
fix: :package: package version updates for generate docs script
nadeem-cs Jun 20, 2023
077dd4c
fix: :adhesive_bandage: updated files list in jsdoc config
nadeem-cs Jun 20, 2023
8ce50b5
fix: added back stack/webhook apis and fixed some routing issues
nadeem-cs Jun 20, 2023
cc1eec8
Merge pull request #56 from contentstack/refactor/CS-38336-Marketplac…
nadeem-cs Jul 5, 2023
b0a6868
feat: :sparkles: adds update fn, auditlog fn, users type correction
nadeem-cs Jul 7, 2023
9d982cc
chore: replaced uid and other data
nadeem-cs Jul 7, 2023
a1ff3b7
Merge pull request #57 from contentstack/feat/CS-39614-adds-nrp-audit…
nadeem-cs Jul 10, 2023
536b6f2
fix: :bug: corrected type of env parameter
nadeem-cs Jul 11, 2023
38de96f
Merge branch 'master' into next
nadeem-cs Jul 14, 2023
72750a0
refactor: adds and corrects types of ContentstackCollectin and market…
nadeem-cs Jul 14, 2023
195d0eb
Merge pull request #61 from contentstack/feat/CS-39614-adds-nrp-audit…
nadeem-cs Jul 14, 2023
269a7ba
fix: credentials in response fix; bulkOperation types fixes;
nadeem-cs Jul 17, 2023
3e437f3
test: :white_check_mark: improves code coverage
nadeem-cs Jul 17, 2023
c40f512
Merge pull request #62 from contentstack/feat/CS-39614-adds-nrp-audit…
ishaileshmishra Jul 17, 2023
a59abdc
Merge pull request #63 from contentstack/bug/env-type-change
nadeem-cs Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: ✅ improves code coverage
  • Loading branch information
nadeem-cs committed Jul 17, 2023
commit 3e437f384f1630fa34050bc8b0ae2fabd0c3dd16
27 changes: 1 addition & 26 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,6 @@ export const create = ({ http, params }) => {
}
}

export const exportObject = ({ http }) => {
return async function (param) {
const headers = {
params: {
...cloneDeep(param)
},
headers: {
...cloneDeep(this.stackHeaders)
}
} || {}
try {
const response = await http.get(this.urlPath, headers)
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid))
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
}

export const query = ({ http, wrapperCollection }) => {
return function (params = {}) {
const headers = {
Expand Down Expand Up @@ -181,9 +158,7 @@ export const deleteEntity = (http, force = false, params = {}) => {
try {
const headers = {
headers: { ...cloneDeep(this.stackHeaders), ...cloneDeep(params) },
params: {
...cloneDeep(param)
}
params: { ...cloneDeep(param) }
} || {}
if (force === true) {
headers.params.force = true
Expand Down
74 changes: 37 additions & 37 deletions lib/stack/contentType/entry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,46 +266,46 @@ export function Entry (http, data) {
}
}
} else {
/**
* @description The Create an entry call creates a new entry for the selected content type.
* @memberof Entry
* @func create
* @returns {Promise<Entry.Entry>} Promise for Entry instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const entry = {
* title: 'Sample Entry',
* url: '/sampleEntry',
* file: 'asset_uid', // for single asset pass asset uid to entry asset field value
* multiple_file = ['asset_uid_1', 'asset_uid_2'], // for multiple asset pass array of asset uid to entry asset field values
* reference: reference.uid, // for single reference pass reference uid to entry reference field value
* multiple_reference: ['reference_uid_1', 'reference_uid_2'], // for multiple reference pass array of reference uid to entry reference field values
* multiple_content_type_reference: [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'}, {_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] // for multiple reference pass array of reference uid to entry reference field values
* }
* client.stack().contentType('content_type_uid').entry().create({ entry })
* .then((entry) => console.log(entry))
*/
/**
* @description The Create an entry call creates a new entry for the selected content type.
* @memberof Entry
* @func create
* @returns {Promise<Entry.Entry>} Promise for Entry instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const entry = {
* title: 'Sample Entry',
* url: '/sampleEntry',
* file: 'asset_uid', // for single asset pass asset uid to entry asset field value
* multiple_file = ['asset_uid_1', 'asset_uid_2'], // for multiple asset pass array of asset uid to entry asset field values
* reference: reference.uid, // for single reference pass reference uid to entry reference field value
* multiple_reference: ['reference_uid_1', 'reference_uid_2'], // for multiple reference pass array of reference uid to entry reference field values
* multiple_content_type_reference: [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'}, {_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] // for multiple reference pass array of reference uid to entry reference field values
* }
* client.stack().contentType('content_type_uid').entry().create({ entry })
* .then((entry) => console.log(entry))
*/
this.create = create({ http: http })

/**
* @description The Query on Entry will allow to fetch details of all or specific Entry
* @memberof Entry
* @func query
* @param {Int} locale Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed.
* @param {Int} include_workflow Enter 'true' to include the workflow details of the entry.
* @param {Int} include_publish_details Enter 'true' to include the publish details of the entry.
* @param {Object} query Queries that you can use to fetch filtered results.
* @returns {Array<Entry>} Array of Entry.
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack().contentType('content_type_uid').entry().query({ query: { title: 'Entry title' } }).find()
* .then((entries) => console.log(entries))
*/
* @description The Query on Entry will allow to fetch details of all or specific Entry
* @memberof Entry
* @func query
* @param {Int} locale Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed.
* @param {Int} include_workflow Enter 'true' to include the workflow details of the entry.
* @param {Int} include_publish_details Enter 'true' to include the publish details of the entry.
* @param {Object} query Queries that you can use to fetch filtered results.
* @returns {Array<Entry>} Array of Entry.
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack().contentType('content_type_uid').entry().query({ query: { title: 'Entry title' } }).find()
* .then((entries) => console.log(entries))
*/
this.query = query({ http: http, wrapperCollection: EntryCollection })
}

Expand Down
10 changes: 5 additions & 5 deletions test/api/stack-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Stack api Test', () => {
})

it('Update Stack details', done => {
const name = 'My New Stack Update Name'
const name = 'Conference Demo'
const description = 'My New description stack'
client.stack({ api_key: stacks.api_key })
.fetch().then((stack) => {
Expand Down Expand Up @@ -130,13 +130,13 @@ describe('Stack api Test', () => {

it('Get query stack', done => {
client.stack()
.query({ query: { name: 'Conference Demo' } })
.query({ query: { name: 'My New Stack Update Name' } })
.find()
.then((response) => {
expect(response.items.length).to.be.equal(1)
for (const index in response.items) {
const stack = response.items[index]
expect(stack.name).to.be.equal('Conference Demo')
expect(stack.name).to.be.equal('My New Stack Update Name')
}
done()
})
Expand All @@ -145,12 +145,12 @@ describe('Stack api Test', () => {

it('Find one stack', done => {
client.stack()
.query({ query: { name: 'Conference Demo' } })
.query({ query: { name: 'My New Stack Update Name' } })
.findOne()
.then((response) => {
const stack = response.items[0]
expect(response.items.length).to.be.equal(1)
expect(stack.name).to.be.equal('Conference Demo')
expect(stack.name).to.be.equal('My New Stack Update Name')
done()
})
.catch(done)
Expand Down
2 changes: 1 addition & 1 deletion test/api/user-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var loggedinUserID = ''
var client = contentstackClient()
describe('Contentstack User Session api Test', () => {
it('User login wrong credentials', done => {
contentstackClient().login({ email: process.env.EMAIL, password: process.env.PASSWORDWRONG })
contentstackClient().login({ email: process.env.EMAIL, password: process.env.PASSWORD })
.then((response) => {
console.log(response)
done()
Expand Down
69 changes: 22 additions & 47 deletions test/unit/ContentstackClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import axios from 'axios'
import httpAdapter from 'axios/lib/adapters/http'
import ContentstackClient from '../../lib/contentstackClient'
import { expect } from 'chai'
import { describe, it, after, beforeEach } from 'mocha'
import nock from 'nock'
import { describe, it, beforeEach } from 'mocha'
import MockAdapter from 'axios-mock-adapter'
var host = 'http://localhost/'

describe('Contentstack Client', () => {
Expand All @@ -12,10 +12,6 @@ describe('Contentstack Client', () => {
axios.defaults.host = host
axios.defaults.adapter = httpAdapter
})
after('all', function () {
nock.restore()
nock.cleanAll()
})

it('Contentstack Client Object successful', done => {
var contentstackClient = ContentstackClient({ http: axios })
Expand All @@ -24,30 +20,12 @@ describe('Contentstack Client', () => {
})

it('Contentstack Client login success', done => {
nock(host)
.post('/user-session', {})
.reply(200, {
user: {
authtoken: 'Test Auth'
}
})
ContentstackClient({ http: axios })
.login()
.then((response) => {
expect(response.user.authtoken).to.be.equal('Test Auth')
done()
})
.catch(done)
})

it('Contentstack Client login success', done => {
nock(host)
.post('/user-session', {})
.reply(200, {
user: {
authtoken: 'Test Auth'
}
})
var mock = new MockAdapter(axios)
mock.onPost('/user-session').reply(200, {
user: {
authtoken: 'Test Auth'
}
})
ContentstackClient({ http: axios })
.login()
.then((response) => {
Expand All @@ -58,13 +36,12 @@ describe('Contentstack Client', () => {
})

it('Contentstack Client get user info', done => {
nock(host)
.get('/user')
.reply(200, {
user: {
uid: 'test uid'
}
})
var mock = new MockAdapter(axios)
mock.onGet('/user').reply(200, {
user: {
uid: 'test uid'
}
})
ContentstackClient({ http: axios })
.getUser()
.then((user) => {
Expand All @@ -75,11 +52,10 @@ describe('Contentstack Client', () => {
})

it('Contentstack Client Logout with Authtoken', done => {
nock(host)
.delete('/user-session')
.reply(200, {
notice: 'You\'ve logged out successfully'
})
var mock = new MockAdapter(axios)
mock.onDelete('/user-session').reply(200, {
notice: 'You\'ve logged out successfully'
})
ContentstackClient({ http: axios })
.logout('Test Auth')
.then((response) => {
Expand All @@ -90,11 +66,10 @@ describe('Contentstack Client', () => {
})

it('Contentstack Client Logout', done => {
nock(host)
.delete('/user-session')
.reply(200, {
notice: 'You\'ve logged out successfully'
})
var mock = new MockAdapter(axios)
mock.onDelete('/user-session').reply(200, {
notice: 'You\'ve logged out successfully'
})
axios.defaults.headers = {
common: {
authtoken: 'Authtoken'
Expand Down
27 changes: 22 additions & 5 deletions test/unit/Util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,28 @@ describe('Get User Agent', () => {
platform: 'MacIntel'
}
}
const userAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1')
expect(userAgent.match(headerRegEx).length).to.be.equal(5)
expect(userAgent.indexOf('platform browser')).to.not.equal(-1)
expect(userAgent.indexOf('os macOS;')).to.not.equal(-1)
const macUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1')
expect(macUserAgent.match(headerRegEx).length).to.be.equal(5)
expect(macUserAgent.indexOf('platform browser')).to.not.equal(-1)
expect(macUserAgent.indexOf('os macOS;')).to.not.equal(-1)

global.window.navigator.platform = 'Windows'
const windowsUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1')
expect(windowsUserAgent.match(headerRegEx).length).to.be.equal(5)
expect(windowsUserAgent.indexOf('platform browser')).to.not.equal(-1)
expect(windowsUserAgent.indexOf('os Windows;')).to.not.equal(-1)

global.window.navigator = { userAgent: 'Android' }
const androidUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1')
expect(androidUserAgent.match(headerRegEx).length).to.be.equal(5)
expect(androidUserAgent.indexOf('platform browser')).to.not.equal(-1)
expect(androidUserAgent.indexOf('os Android;')).to.not.equal(-1)

global.window.navigator = { platform: 'Linux' }
const linuxUserAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1')
expect(linuxUserAgent.match(headerRegEx).length).to.be.equal(5)
expect(linuxUserAgent.indexOf('platform browser')).to.not.equal(-1)
expect(linuxUserAgent.indexOf('os Linux;')).to.not.equal(-1)
done()

getUserAgentRewireApi.__ResetDependency__('isNode')
Expand All @@ -40,7 +58,6 @@ describe('Get User Agent', () => {
global.window = {}

const userAgent = getUserAgent('contentstack-sdk/1.0.0', 'SampleApplication/0.1', 'SampleIntegration/0,1')

expect(userAgent.match(headerRegEx).length).to.be.equal(3)
expect(userAgent.indexOf('platform browser')).to.equal(-1)
expect(userAgent.indexOf('os macOS;')).to.equal(-1)
Expand Down
33 changes: 30 additions & 3 deletions test/unit/apps-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,18 @@ describe('Contentstack apps test', () => {
installations.items.forEach(installation => {
checkInstallation(installation)
})
done()
})
.catch(done)

// Failing test
mock.onGet(`manifests/${uid}/installations`).reply(400, {})
makeApp({ data: { uid } })
.listInstallations()
.then()
.catch((error) => {
expect(error).to.not.equal(null)
done()
})
})

it('app install test', done => {
Expand All @@ -170,9 +179,18 @@ describe('Contentstack apps test', () => {
expect(installation.target.uid).to.be.equal(installationMock.target.uid)
expect(installation.organization_uid).to.be.equal(installationMock.organization_uid)
expect(installation.uid).to.be.equal(installationMock.uid)
done()
})
.catch(done)

// Failing test
mock.onPost(`/manifests/${uid}/install`).reply(400, {})
makeApp({ data: { uid } })
.install({ targetUid, targetType })
.then()
.catch((error) => {
expect(error).to.not.equal(null)
done()
})
})

it('app upgrade test', done => {
Expand All @@ -193,9 +211,18 @@ describe('Contentstack apps test', () => {
expect(installation.target.uid).to.be.equal(installationMock.target.uid)
expect(installation.organization_uid).to.be.equal(installationMock.organization_uid)
expect(installation.uid).to.be.equal(installationMock.uid)
done()
})
.catch(done)

// Failing test
mock.onPut(`/manifests/${uid}/reinstall`).reply(400, {})
makeApp({ data: { uid } })
.upgrade({ targetUid, targetType })
.then()
.catch((error) => {
expect(error).to.not.equal(null)
done()
})
})

it('test fetch request for app uid', (done) => {
Expand Down
Loading