Skip to content

Commit

Permalink
Merge pull request #139 from contentstack/feat/cs-44545-get-languages…
Browse files Browse the repository at this point in the history
…-implementation

get languages of an entry
  • Loading branch information
harshithad0703 authored Apr 3, 2024
2 parents 95e1a45 + b9041d0 commit 6a79fa3
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [v1.16.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-04-09)
- Feature
- Get languages of an entry
## [v1.15.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-03-28)
- Fixes and Enhancement
- delete stack implemetation and test cases
Expand Down
30 changes: 30 additions & 0 deletions lib/stack/contentType/entry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export function Entry (http, data) {
* client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').setWorkflowStage({ workflow_stage, locale: 'en-us'})
* .then((response) => console.log(response.notice));
*/

this.setWorkflowStage = async ({ workflow_stage, locale }) => {
const publishDetails = {
workflow: { workflow_stage }
Expand All @@ -265,6 +266,35 @@ export function Entry (http, data) {
throw error(err)
}
}

/**
* @description The get locales request allows to get the languages of an entry.
* @memberof Entry
* @func locales
* @returns {Promise<Object>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid').locales()
* .then((response) => console.log(response));
*/
this.locales = async () => {
const headers = {}
if (this.stackHeaders) {
headers.headers = this.stackHeaders
}
try {
const response = await http.get(`${this.urlPath}/locales`, headers)
if (response.data) {
return response.data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
} else {
/**
* @description The Create an entry call creates a new entry for the selected content type.
Expand Down
4 changes: 2 additions & 2 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.4",
"version": "1.16.0",
"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
12 changes: 12 additions & 0 deletions test/sanity-check/api/entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ describe('Entry api Test', () => {
.catch(done)
})

it('should get languages of the given Entry uid', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD).locales()
.then((locale) => {
expect(locale.locales[0].code).to.be.equal('en-us')
locale.locales.forEach((locales) => {
expect(locales.code).to.be.not.equal(null)
})
done()
})
.catch(done)
})

it('should unpublish localized entry', done => {
makeEntry(singlepageCT.content_type.uid, entryUTD)
.unpublish({ publishDetails: {
Expand Down
32 changes: 32 additions & 0 deletions test/unit/entry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,38 @@ describe('Contentstack Entry test', () => {
expect(result).to.deep.equal(expectedResult);
done();
})

it('should get languages of the given Entry uid', done => {
var mock = new MockAdapter(Axios)
const locales = [
{
code: 'en-us'
},
{
code: 'hi-in'
},
{
code: 'en-at',
localized: true
},
{
code: 'ja-jp'
}
]
mock.onGet('/content_types/content_type_uid/entries/UID/locales').reply(200, {
locales
})

makeEntry({ entry: { ...systemUidMock }, stackHeaders: stackHeadersMock }).locales()
.then((locale) => {
expect(locale.locales[0].code).to.be.equal('en-us')
locale.locales.forEach((locales) => {
expect(locales.code).to.be.not.equal(null)
})
done()
})
.catch(done)
})
})

function makeEntry (data) {
Expand Down

0 comments on commit 6a79fa3

Please sign in to comment.