Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 26 additions & 2 deletions src/bundles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ export class Bundles extends CrowdinApi {
/**
* @param projectId project identifier
* @param bundleId bundle identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post
*/
exportBundle(projectId: number, bundleId: number): Promise<ResponseObject<Status<BundlesModel.ExportAttributes>>> {
exportBundle(
projectId: number,
bundleId: number,
request?: BundlesModel.ExportBundleRequest,
): Promise<ResponseObject<Status<BundlesModel.ExportAttributes>>> {
const url = `${this.url}/projects/${projectId}/bundles/${bundleId}/exports`;
return this.post(url, undefined, this.defaultConfig());
return this.post(url, request, this.defaultConfig());
}

/**
Expand Down Expand Up @@ -164,7 +169,26 @@ export namespace BundlesModel {
excludeLabelIds?: number[];
}

export interface ExportBundleRequest {
targetLanguageIds?: string[];
skipUntranslatedStrings?: boolean;
skipUntranslatedFiles?: boolean;
// community
exportApprovedOnly?: boolean;
// enterprise
exportWithMinApprovalsCount?: number;
exportStringsThatPassedWorkflow?: boolean;
}

export interface ExportAttributes {
bundleId: number;
targetLanguageIds?: string[];
skipUntranslatedStrings?: boolean;
skipUntranslatedFiles?: boolean;
// community
exportApprovedOnly?: boolean;
// enterprise
exportWithMinApprovalsCount?: number;
exportStringsThatPassedWorkflow?: boolean;
}
}
52 changes: 47 additions & 5 deletions tests/bundles/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,35 @@ describe('Bundles API', () => {
url: exportUrl,
},
})
.post(`/projects/${projectId}/bundles/${bundleId}/exports`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
.post(
`/projects/${projectId}/bundles/${bundleId}/exports`,
{
targetLanguageIds: ['uk'],
skipUntranslatedStrings: false,
exportApprovedOnly: true,
},
})
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
identifier: exportId,
status: 'finished',
progress: 100,
attributes: {
bundleId,
targetLanguageIds: ['uk'],
skipUntranslatedStrings: false,
skipUntranslatedFiles: false,
exportApprovedOnly: true,
},
createdAt: '2019-09-23T11:26:54+00:00',
updatedAt: '2019-09-23T11:26:54+00:00',
startedAt: null,
finishedAt: '2019-09-23T11:26:54+00:00',
},
})
.get(`/projects/${projectId}/bundles/${bundleId}/exports/${exportId}`, undefined, {
Expand All @@ -123,6 +144,19 @@ describe('Bundles API', () => {
.reply(200, {
data: {
identifier: exportId,
status: 'finished',
progress: 100,
attributes: {
bundleId,
targetLanguageIds: ['uk'],
skipUntranslatedStrings: false,
skipUntranslatedFiles: false,
exportApprovedOnly: true,
},
createdAt: '2019-09-23T11:26:54+00:00',
updatedAt: '2019-09-23T11:26:54+00:00',
startedAt: null,
finishedAt: '2019-09-23T11:26:54+00:00',
},
})
.get(`/projects/${projectId}/bundles/${bundleId}/files`, undefined, {
Expand Down Expand Up @@ -210,13 +244,21 @@ describe('Bundles API', () => {
});

it('Export bundle', async () => {
const resp = await api.exportBundle(projectId, bundleId);
const resp = await api.exportBundle(projectId, bundleId, {
targetLanguageIds: ['uk'],
skipUntranslatedStrings: false,
exportApprovedOnly: true,
});
expect(resp.data.identifier).toBe(exportId);
expect(resp.data.attributes.exportApprovedOnly).toBe(true);
expect(resp.data.startedAt).toBeNull();
});

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

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