Skip to content

Commit

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

types support for get locales
  • Loading branch information
harshithad0703 authored Apr 3, 2024
2 parents a2033e9 + 3df19c3 commit fba2183
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
18 changes: 17 additions & 1 deletion test/typescript/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function getEntries(stack: Stack) {
})

test('Fetch Entry', done => {
stack.contentType(singlepageCT.content_type.uid).entry(entryUTD)
stack.contentType('product').entry('blt7d6fae845bfc55d4')
.fetch({include_content_type: true})
.then((response) => {
expect(response.uid).to.be.not.equal(null)
Expand Down Expand Up @@ -132,6 +132,22 @@ export function getEntries(stack: Stack) {
})
}

export function getEntryLocales(stack: Stack) {
describe('Entry get', () => {
test('to get locales of an entry', done => {
stack.contentType(singlepageCT.content_type.uid).entry(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)
})
})
}

export function publishUnpublishEntry(stack: Stack) {
describe('Unpublish/Publish Entry', () => {
test('Publish Entry', done => {
Expand Down
3 changes: 2 additions & 1 deletion test/typescript/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { organization, organizations } from './organization';
import * as dotenv from 'dotenv'
import { shareStack, stacks, stackTest, unshareStack } from './stack';
import { contentType, createContentType, queryContentType } from './contentType';
import { createEntry, getEntries, importEntry, publishUnpublishEntry } from './entry';
import { createEntry, getEntries, importEntry, publishUnpublishEntry, getEntryLocales } from './entry';
import { createAsset, deleteAsset, downloadAsset, getAssets, publishUnpublishAsset, queryOnAsset, replaceAsset } from './asset';
import { createGlobalField, globalField, queryGlobalField } from './globalField';
import { createBranch, deleteBranch, queryBranch } from './branch';
Expand Down Expand Up @@ -103,6 +103,7 @@ describe('Typescript API test', () => {

createEntry(stack)
getEntries(stack)
getEntryLocales(stack)
publishUnpublishEntry(stack)
importEntry(stack)

Expand Down
10 changes: 10 additions & 0 deletions types/stack/contentType/entry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Unpublishable } from "../../utility/unpublish";

export interface Entry extends Publishable, Unpublishable, SystemFields, SystemFunction<Entry> {
setWorkflowStage(data: { workflow_stage: WorkflowStage, locale?:string}): Promise<Response>
locales(): Promise<Locales>
}

export interface Entries extends Queryable<Entry, {entry: EntryData}> {
Expand All @@ -25,4 +26,13 @@ export interface WorkflowStage extends AnyProperty {
notify?: boolean
assign_to?: Array<any>
assigned_by_roles?: Array<any>
}

export interface Locales {
locales: Code[];
}

export interface Code extends AnyProperty {
code: string;
localized: boolean;
}

0 comments on commit fba2183

Please sign in to comment.