Skip to content

Commit ffaee8d

Browse files
fix(screenshots): align API params and tag response type (#669)
1 parent 96798ba commit ffaee8d

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/screenshots/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class Screenshots extends CrowdinApi {
3737
options = { limit: options, offset: deprecatedOffset };
3838
}
3939
let url = `${this.url}/projects/${projectId}/screenshots`;
40+
url = this.addQueryParam(url, 'search', options.search);
4041
url = this.addQueryParam(url, 'stringIds', options.stringIds?.join(','));
4142
url = this.addQueryParam(url, 'stringId', options.stringId);
4243
url = this.addQueryParam(url, 'labelIds', options.labelIds);
@@ -220,14 +221,15 @@ export class Screenshots extends CrowdinApi {
220221
screenshotId: number,
221222
tagId: number,
222223
request: PatchRequest[],
223-
): Promise<ResponseObject<ScreenshotsModel.Screenshot>> {
224+
): Promise<ResponseObject<ScreenshotsModel.Tag>> {
224225
const url = `${this.url}/projects/${projectId}/screenshots/${screenshotId}/tags/${tagId}`;
225226
return this.patch(url, request, this.defaultConfig());
226227
}
227228
}
228229

229230
export namespace ScreenshotsModel {
230231
export interface ListScreenshotParams extends PaginationOptions {
232+
search?: string;
231233
stringIds?: number[];
232234
/**
233235
* @deprecated use stringIds instead
@@ -266,6 +268,7 @@ export namespace ScreenshotsModel {
266268
export interface UpdateScreenshotRequest {
267269
storageId: number;
268270
name: string;
271+
usePreviousTags?: boolean;
269272
}
270273

271274
export interface Tag {

tests/screenshots/api.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('Screenshots API', () => {
7272
{
7373
storageId: storageId,
7474
name: screenshotName,
75+
usePreviousTags: true,
7576
},
7677
{
7778
reqheaders: {
@@ -204,7 +205,7 @@ describe('Screenshots API', () => {
204205
)
205206
.reply(200, {
206207
data: {
207-
id: screenshotId,
208+
id: tagId,
208209
},
209210
});
210211
});
@@ -221,6 +222,36 @@ describe('Screenshots API', () => {
221222
expect(screenshots.pagination.limit).toBe(limit);
222223
});
223224

225+
it('List screenshots with search filter', async () => {
226+
const listWithSearchScope = nock(api.url, {
227+
reqheaders: {
228+
Authorization: `Bearer ${api.token}`,
229+
},
230+
})
231+
.get(`/projects/${projectId}/screenshots`)
232+
.query({
233+
search: screenshotName,
234+
})
235+
.reply(200, {
236+
data: [
237+
{
238+
data: {
239+
id: screenshotId,
240+
name: screenshotName,
241+
},
242+
},
243+
],
244+
pagination: {
245+
offset: 0,
246+
limit: limit,
247+
},
248+
});
249+
const screenshots = await api.listScreenshots(projectId, { search: screenshotName });
250+
expect(screenshots.data.length).toBe(1);
251+
expect(screenshots.data[0].data.id).toBe(screenshotId);
252+
listWithSearchScope.done();
253+
});
254+
224255
it('Add screenshot', async () => {
225256
const screenshot = await api.addScreenshot(projectId, {
226257
name: screenshotName,
@@ -240,6 +271,7 @@ describe('Screenshots API', () => {
240271
const screenshot = await api.updateScreenshot(projectId, screenshotId, {
241272
storageId: storageId,
242273
name: screenshotName,
274+
usePreviousTags: true,
243275
});
244276
expect(screenshot.data.id).toBe(screenshotId);
245277
expect(screenshot.data.name).toBe(screenshotName);
@@ -309,6 +341,6 @@ describe('Screenshots API', () => {
309341
value: stringId,
310342
},
311343
]);
312-
expect(tag.data.id).toBe(screenshotId);
344+
expect(tag.data.id).toBe(tagId);
313345
});
314346
});

0 commit comments

Comments
 (0)