Skip to content

Commit

Permalink
fix(v3proxy): update default page size for since queries to 5000
Browse files Browse the repository at this point in the history
Fix incorrect state name (archived/archive) and access using
typescript-checkable method
  • Loading branch information
kschelonka committed Jan 7, 2025
1 parent 591b18e commit 3758a43
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
4 changes: 2 additions & 2 deletions servers/v3-proxy-api/src/graph/get/toGraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export function SavedItemsSortFactory(params: V3GetParams) {
if (params.favorite != null) {
sortBy = SavedItemsSortBy.FavoritedAt;
} else if (
params.state &&
['read', 'archived'].indexOf(params.state) > -1
(params.state && params.state === 'read') ||
params.state === 'archive'
) {
sortBy = SavedItemsSortBy.ArchivedAt;
}
Expand Down
25 changes: 25 additions & 0 deletions servers/v3-proxy-api/src/routes/v3Get.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,31 @@ describe('v3Get', () => {
expect(apiSpy.mock.lastCall?.[3].filter?.updatedSince).toEqual(123123);
expect(response.headers['x-source']).toBe(expectedHeaders['X-Source']);
});
it('should set count to 5000 if `since` parameter is passed', async () => {
const apiSpy = jest
.spyOn(GraphQLCalls, 'callSavedItemsByOffsetComplete')
.mockImplementation(() => Promise.resolve(mockGraphGetComplete));
const response = await request(app).get('/v3/get').query({
consumer_key: 'test',
access_token: 'test',
since: '123123',
detailType: 'complete',
});
expect(apiSpy.mock.lastCall?.[3].pagination?.limit).toEqual(5000);
expect(response.headers['x-source']).toBe(expectedHeaders['X-Source']);
});
it('should set count to 30 if no `since` parameter', async () => {
const apiSpy = jest
.spyOn(GraphQLCalls, 'callSavedItemsByOffsetComplete')
.mockImplementation(() => Promise.resolve(mockGraphGetComplete));
const response = await request(app).get('/v3/get').query({
consumer_key: 'test',
access_token: 'test',
detailType: 'complete',
});
expect(apiSpy.mock.lastCall?.[3].pagination?.limit).toEqual(30);
expect(response.headers['x-source']).toBe(expectedHeaders['X-Source']);
});
it('should not add contentType filter if value="all"', async () => {
const apiSpy = jest
.spyOn(GraphQLCalls, 'callSavedItemsByOffsetComplete')
Expand Down
36 changes: 24 additions & 12 deletions servers/v3-proxy-api/src/routes/validations/GetSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ export const V3GetSchema: Schema = {
},
toInt: true,
},
count: {
default: {
options: 30,
},
isInt: {
options: {
min: 1,
max: 5000,
},
},
toInt: true,
},
tag: {
optional: true,
isString: true,
Expand All @@ -116,6 +104,30 @@ export const V3GetSchema: Schema = {
options: (value) => timeSeconds(value),
},
},
count: {
toInt: true,
customSanitizer: {
options: (value, { req }) => {
const hasSince =
req.body.since != null || req.query?.since != null ? true : false;
// Android client does not paginate results for 'since'
if (value == null || value === '' || Number.isNaN(value)) {
if (hasSince) {
return 5000;
} else {
return 30;
}
}
return value;
},
},
isInt: {
options: {
min: 1,
max: 5000,
},
},
},
updatedBefore: {
optional: true,
isInt: {
Expand Down

0 comments on commit 3758a43

Please sign in to comment.