Skip to content

Commit c5ff88c

Browse files
authored
feat: add internal workflow step string status management methods (#572)
1 parent 7b108d1 commit c5ff88c

2 files changed

Lines changed: 114 additions & 1 deletion

File tree

src/workflows/index.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CrowdinApi, isOptionalNumber, PaginationOptions, ResponseList, ResponseObject } from '../core';
1+
import { CrowdinApi, isOptionalNumber, PaginationOptions, PatchRequest, ResponseList, ResponseObject } from '../core';
22
import { SourceStringsModel } from '../sourceStrings';
33

44
/**
@@ -109,6 +109,42 @@ export class Workflows extends CrowdinApi {
109109
const url = `${this.url}/workflow-templates/${templateId}`;
110110
return this.get(url, this.defaultConfig());
111111
}
112+
113+
/**
114+
* @param projectId project identifier
115+
* @param stepId workflow step identifier
116+
* @param languageId language identifier
117+
* @param request request body
118+
* @internal
119+
* @see https://support.crowdin.com/developer/crowdin-apps-module-workflow-step-type/#api-methods
120+
*/
121+
updateWorkflowStepStringStatus(
122+
projectId: number,
123+
stepId: number,
124+
languageId: string,
125+
request: PatchRequest[],
126+
): Promise<ResponseList<WorkflowModel.WorkflowStepStringStatus>> {
127+
const url = `${this.url}/projects/${projectId}/workflow-steps/${stepId}/languages/${languageId}/status`;
128+
return this.patch(url, request, this.defaultConfig());
129+
}
130+
131+
/**
132+
* @param projectId project identifier
133+
* @param stepId workflow step identifier
134+
* @param languageId language identifier
135+
* @param options request options
136+
* @internal
137+
* @see https://support.crowdin.com/developer/crowdin-apps-module-workflow-step-type/#api-methods
138+
*/
139+
getWorkflowStepStringStatus(
140+
projectId: number,
141+
stepId: number,
142+
languageId: string,
143+
options?: PaginationOptions,
144+
): Promise<ResponseList<WorkflowModel.WorkflowStepStringStatus>> {
145+
const url = `${this.url}/projects/${projectId}/workflow-steps/${stepId}/languages/${languageId}/status`;
146+
return this.getList(url, options?.limit, options?.offset);
147+
}
112148
}
113149

114150
export namespace WorkflowModel {
@@ -151,4 +187,12 @@ export namespace WorkflowModel {
151187
mtId: number;
152188
}[];
153189
}
190+
191+
export interface WorkflowStepStringStatus {
192+
stringId: number;
193+
languageId: string;
194+
stepId: number;
195+
status: string;
196+
output: string;
197+
}
154198
}

tests/workflows/api.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('Workflows API', () => {
1111
const id = 2;
1212
const projectId = 4;
1313
const stringId = 123;
14+
const languageId = 'uk';
1415

1516
const limit = 25;
1617

@@ -89,6 +90,46 @@ describe('Workflows API', () => {
8990
data: {
9091
id: id,
9192
},
93+
})
94+
.get(`/projects/${projectId}/workflow-steps/${id}/languages/${languageId}/status`, undefined, {
95+
reqheaders: {
96+
Authorization: `Bearer ${api.token}`,
97+
},
98+
})
99+
.reply(200, {
100+
data: [
101+
{
102+
data: {
103+
stringId: stringId,
104+
languageId: languageId,
105+
stepId: id,
106+
status: 'DONE',
107+
output: 'translated',
108+
},
109+
},
110+
],
111+
pagination: {
112+
offset: 0,
113+
limit: limit,
114+
},
115+
})
116+
.patch(`/projects/${projectId}/workflow-steps/${id}/languages/${languageId}/status`, undefined, {
117+
reqheaders: {
118+
Authorization: `Bearer ${api.token}`,
119+
},
120+
})
121+
.reply(200, {
122+
data: [
123+
{
124+
data: {
125+
stringId: stringId,
126+
languageId: languageId,
127+
stepId: id,
128+
status: 'DONE',
129+
output: 'approved',
130+
},
131+
},
132+
],
92133
});
93134
});
94135

@@ -126,4 +167,32 @@ describe('Workflows API', () => {
126167
const workflow = await api.getWorkflowTemplateInfo(id);
127168
expect(workflow.data.id).toBe(id);
128169
});
170+
171+
it('Get Workflow Step String Status', async () => {
172+
const stringStatuses = await api.getWorkflowStepStringStatus(projectId, id, languageId);
173+
expect(stringStatuses.data.length).toBe(1);
174+
expect(stringStatuses.data[0].data.stringId).toBe(stringId);
175+
expect(stringStatuses.data[0].data.languageId).toBe(languageId);
176+
expect(stringStatuses.data[0].data.stepId).toBe(id);
177+
expect(stringStatuses.data[0].data.status).toBe('DONE');
178+
expect(stringStatuses.data[0].data.output).toBe('translated');
179+
expect(stringStatuses.pagination.limit).toBe(limit);
180+
});
181+
182+
it('Update Workflow Step String Status', async () => {
183+
const request = [
184+
{
185+
op: 'replace' as const,
186+
path: `/${stringId}/output`,
187+
value: 'approved',
188+
},
189+
];
190+
const result = await api.updateWorkflowStepStringStatus(projectId, id, languageId, request);
191+
expect(result.data.length).toBe(1);
192+
expect(result.data[0].data.stringId).toBe(stringId);
193+
expect(result.data[0].data.languageId).toBe(languageId);
194+
expect(result.data[0].data.stepId).toBe(id);
195+
expect(result.data[0].data.status).toBe('DONE');
196+
expect(result.data[0].data.output).toBe('approved');
197+
});
129198
});

0 commit comments

Comments
 (0)