Skip to content

Conversation

@mmiermans
Copy link
Contributor

@mmiermans mmiermans commented Jul 13, 2023

Goal

Add a backward-compatible NewTab recommendation endpoint /v3/firefox/global-recs.

I'd love feedback/perspectives on:

  • Test coverage
  • Naming conventions

References

JIRA ticket:

Documentation:

@mmiermans mmiermans requested a review from Herraj July 13, 2023 21:42
@mmiermans mmiermans requested review from a team as code owners July 13, 2023 21:42
@mmiermans mmiermans requested a review from bassrock July 13, 2023 21:42
Copy link
Contributor

@bassrock bassrock left a 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.

Copy link

@jeshuaborges jeshuaborges left a 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({

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', () => {

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.

describe('response', () => {
it('ajv returns errors when bad objects', () => {
const valid = validate({});
expect(!valid).toBeTruthy();

This comment was marked as resolved.

Copy link
Contributor Author

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

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.

Copy link
Contributor

@Herraj Herraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Comment on lines +201 to +206
startTime:
type: integer
endTime:
type: integer
weightPosition:
type: number
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines +46 to +56
expect(errors).toEqual(
expect.objectContaining<APIErrorResponse>({
errors: expect.arrayContaining<Array<APIError>>([
expect.objectContaining<APIError>({
status: '400',
title: 'Bad Request',
}),
]),
})
);
});
Copy link
Contributor

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 🤔

Copy link
Contributor Author

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`,
Copy link
Contributor

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',
Copy link
Contributor

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?

Copy link
Contributor Author

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..

@mmiermans mmiermans merged commit 34b87d0 into main Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants