Skip to content

Commit 1f277bc

Browse files
feat(bundles): add export settings to export bundle (#680)
1 parent d2fd74d commit 1f277bc

2 files changed

Lines changed: 73 additions & 7 deletions

File tree

src/bundles/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ export class Bundles extends CrowdinApi {
8282
/**
8383
* @param projectId project identifier
8484
* @param bundleId bundle identifier
85+
* @param request request body
8586
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post
8687
*/
87-
exportBundle(projectId: number, bundleId: number): Promise<ResponseObject<Status<BundlesModel.ExportAttributes>>> {
88+
exportBundle(
89+
projectId: number,
90+
bundleId: number,
91+
request?: BundlesModel.ExportBundleRequest,
92+
): Promise<ResponseObject<Status<BundlesModel.ExportAttributes>>> {
8893
const url = `${this.url}/projects/${projectId}/bundles/${bundleId}/exports`;
89-
return this.post(url, undefined, this.defaultConfig());
94+
return this.post(url, request, this.defaultConfig());
9095
}
9196

9297
/**
@@ -164,7 +169,26 @@ export namespace BundlesModel {
164169
excludeLabelIds?: number[];
165170
}
166171

172+
export interface ExportBundleRequest {
173+
targetLanguageIds?: string[];
174+
skipUntranslatedStrings?: boolean;
175+
skipUntranslatedFiles?: boolean;
176+
// community
177+
exportApprovedOnly?: boolean;
178+
// enterprise
179+
exportWithMinApprovalsCount?: number;
180+
exportStringsThatPassedWorkflow?: boolean;
181+
}
182+
167183
export interface ExportAttributes {
168184
bundleId: number;
185+
targetLanguageIds?: string[];
186+
skipUntranslatedStrings?: boolean;
187+
skipUntranslatedFiles?: boolean;
188+
// community
189+
exportApprovedOnly?: boolean;
190+
// enterprise
191+
exportWithMinApprovalsCount?: number;
192+
exportStringsThatPassedWorkflow?: boolean;
169193
}
170194
}

tests/bundles/api.test.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,35 @@ describe('Bundles API', () => {
105105
url: exportUrl,
106106
},
107107
})
108-
.post(`/projects/${projectId}/bundles/${bundleId}/exports`, undefined, {
109-
reqheaders: {
110-
Authorization: `Bearer ${api.token}`,
108+
.post(
109+
`/projects/${projectId}/bundles/${bundleId}/exports`,
110+
{
111+
targetLanguageIds: ['uk'],
112+
skipUntranslatedStrings: false,
113+
exportApprovedOnly: true,
111114
},
112-
})
115+
{
116+
reqheaders: {
117+
Authorization: `Bearer ${api.token}`,
118+
},
119+
},
120+
)
113121
.reply(200, {
114122
data: {
115123
identifier: exportId,
124+
status: 'finished',
125+
progress: 100,
126+
attributes: {
127+
bundleId,
128+
targetLanguageIds: ['uk'],
129+
skipUntranslatedStrings: false,
130+
skipUntranslatedFiles: false,
131+
exportApprovedOnly: true,
132+
},
133+
createdAt: '2019-09-23T11:26:54+00:00',
134+
updatedAt: '2019-09-23T11:26:54+00:00',
135+
startedAt: null,
136+
finishedAt: '2019-09-23T11:26:54+00:00',
116137
},
117138
})
118139
.get(`/projects/${projectId}/bundles/${bundleId}/exports/${exportId}`, undefined, {
@@ -123,6 +144,19 @@ describe('Bundles API', () => {
123144
.reply(200, {
124145
data: {
125146
identifier: exportId,
147+
status: 'finished',
148+
progress: 100,
149+
attributes: {
150+
bundleId,
151+
targetLanguageIds: ['uk'],
152+
skipUntranslatedStrings: false,
153+
skipUntranslatedFiles: false,
154+
exportApprovedOnly: true,
155+
},
156+
createdAt: '2019-09-23T11:26:54+00:00',
157+
updatedAt: '2019-09-23T11:26:54+00:00',
158+
startedAt: null,
159+
finishedAt: '2019-09-23T11:26:54+00:00',
126160
},
127161
})
128162
.get(`/projects/${projectId}/bundles/${bundleId}/files`, undefined, {
@@ -210,13 +244,21 @@ describe('Bundles API', () => {
210244
});
211245

212246
it('Export bundle', async () => {
213-
const resp = await api.exportBundle(projectId, bundleId);
247+
const resp = await api.exportBundle(projectId, bundleId, {
248+
targetLanguageIds: ['uk'],
249+
skipUntranslatedStrings: false,
250+
exportApprovedOnly: true,
251+
});
214252
expect(resp.data.identifier).toBe(exportId);
253+
expect(resp.data.attributes.exportApprovedOnly).toBe(true);
254+
expect(resp.data.startedAt).toBeNull();
215255
});
216256

217257
it('Check bundle export status', async () => {
218258
const resp = await api.checkBundleExportStatus(projectId, bundleId, exportId);
219259
expect(resp.data.identifier).toBe(exportId);
260+
expect(resp.data.attributes.targetLanguageIds).toEqual(['uk']);
261+
expect(resp.data.finishedAt).toBe('2019-09-23T11:26:54+00:00');
220262
});
221263

222264
it('Bundle list files', async () => {

0 commit comments

Comments
 (0)