-
Notifications
You must be signed in to change notification settings - Fork 0
feat(GlobalRecs): Add /v3/firefox/global-recs API #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bassrock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmiermans this looks right to me, but i'm gonna defer a 🟢 to someone a bit closer to this code. If I happen to be that person still ping me and i'll check the box.
jeshuaborges
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me. I love the strategy of getting the endpoint set up with mocks as a first PR.
| return next(variables); | ||
| } | ||
|
|
||
| const graphRes = await Recommendations({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future enhancement it: Given all requests in this repo is probably forwarding a request to the graph it would be great to have either a middleware or some factory to generate a graph client for us with all of the authentication parameters already handled.
|
|
||
| import { APIError, APIErrorResponse, BFFFxError } from '../../bfffxError'; | ||
|
|
||
| describe('input.ts recommendations query parameters', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great example of tests and covering all the conditionals in your unit tests.
src/api/v3/response.spec.ts
Outdated
| describe('response', () => { | ||
| it('ajv returns errors when bad objects', () => { | ||
| const valid = validate({}); | ||
| expect(!valid).toBeTruthy(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copy-pasted these tests from the v1/desktop/recommendations endpoint. 😏
| }); | ||
|
|
||
| describe('responseTransformer', () => { | ||
| // all fields are non-nullable, not much to test other than happy path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other tests but you are handling those in your other unit tests.
Herraj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
| startTime: | ||
| type: integer | ||
| endTime: | ||
| type: integer | ||
| weightPosition: | ||
| type: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have little context around this but if we mean to represent these types as Typescript types then we'll have to use number for all of them 🤔
Unless this is just for the openapi schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is an openapi schema, which distinguishes between integers and floating-point numbers.
| expect(errors).toEqual( | ||
| expect.objectContaining<APIErrorResponse>({ | ||
| errors: expect.arrayContaining<Array<APIError>>([ | ||
| expect.objectContaining<APIError>({ | ||
| status: '400', | ||
| title: 'Bad Request', | ||
| }), | ||
| ]), | ||
| }) | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Wondering if we can use toMatchObject like above 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copy-pasted these, so I'm not 100% sure, but I believe that APIError contains additional attributes that we didn't want to lock in tests? I don't know which one is better in this case.
| excerpt: recommendation.corpusItem.excerpt, | ||
| domain: recommendation.corpusItem.publisher, | ||
| raw_image_src: recommendation.corpusItem.imageUrl, | ||
| image_src: `https://img-getpocket.cdn.mozilla.net/direct?url=${encodedImageUrl}&resize=w450`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if we don't expect this url to change we can throw it somewhere in a config file too but it's fine this way too.
| ], | ||
| recsExpireTime: 5400, | ||
| spocsPerNewTabs: 0.5, | ||
| version: '6f605b0212069b4b8d3d040faf55742061a25c16', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also always remain the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I should probably add a comment..
Goal
Add a backward-compatible NewTab recommendation endpoint /v3/firefox/global-recs.
I'd love feedback/perspectives on:
References
JIRA ticket:
Documentation: