Sitelet https://github.com/lendkey/interview-react/pull/1
Skip to content

React Interview test submission - #1

Open
elliotgonzalez123 wants to merge 4 commits into
lendkey:masterfrom
elliotgonzalez123:changes
Open

elliotgonzalez123 wants to merge 4 commits into
lendkey:masterfrom
elliotgonzalez123:changes

Conversation

@elliotgonzalez123

Copy link
Copy Markdown

Acceptance Criteria:

When I visit the app, I should see a list of rockets.
The list of rockets should match the first page of results from GET https://launchlibrary.net/1.4/rocket?mode=list

Elliot: All rockets from the live API are displaying on the main page as requested.

Technical Notes
Replace the simulated API call with a real API call to https://launchlibrary.net/1.4/rocket?mode=list. This should be done in the getRocketsList function of src/api/rockets/index.ts.

Elliot: All done.

The previous developer couldn't figure out how to write working tests for the (fake) API calls, so our test coverage isn't at 100%. Perhaps when you implement the real API calls, you will have more success.

Elliot: Mocked axios API calls and my test runner is showing 100% coverage, and all tests passing.

Be sure to enable eslint linting in your editor!

Elliot: This took some time, haha. I normally use single quotes and no semi colons (I know, I know), so I had edit prettier to comply with eslint.

Thanks again guys! If I don't speak to you before the end of the week, have a great rest of your week!

@jmooserific jmooserific left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, @elliotgonzalez123.

Thanks for working on this! The following is how I would reply if you worked at LendKey.

Your pull request definitely meets the Acceptance Criteria in the ticket. Good job! 👍 I can tell you have some TypeScript experience.

Unfortunately, this doesn't meet our code quality standards because the test coverage isn't actually at 100%. (I suspect that you were running npm test in "watch" mode, so it wasn't calculating test coverage for the whole app, but just for your changes.) Try running it like this instead: CI=true nom test. If you merge in my most recent change from the original repo, I made this a little easier by ignoring serviceWorker.ts when calculating test coverage.

You also left a couple of debugging console.log()s behind. We usually remove things like that before deploying our code.

Feel free to delete my sample code instead of commenting it out. Pretend like you own this codebase and will be maintaining it! 💪

You are welcome to make changes, just like in the real world. If anything I said doesn't make sense, please feel free to ask questions here. Thanks!

const { getAllByRole } = within(table);
expect(getAllByRole("columnheader")).toHaveLength(3);
expect(getAllByRole("row")).toHaveLength(5);
expect(getAllByRole("row")).toHaveLength(31);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is still making a real API call. (As you mentioned above, this makes your test slow and fragile.) Please update this test so that the API call is mocked, just like you did in src/api/rockets/index.test.ts.

I might add two more "integration-y" tests here. "With no results", where your axios mock returns an empty array of rockets, and "With errors", where your axios mock returns an error. You could then get rid of the two super fake tests below.

There's an example of mocking a network error here.

Comment thread src/api/rockets/index.ts
try {
const data: JsonResponse = JSON.parse(await getRockets());
//I do not believe parsing an axios response is necessary so I removed it.
//Had to troubleshoot for a few minutes why data was not passing through, the culprit was the parse function.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Exactly right. Axios parses the JSON for you.

Comment thread src/api/rockets/index.ts
// Simulate calling the API endpoint https://launchlibrary.net/1.4/rocket?mode=list
export const getRockets = async () => {
//leaving this in for dramatic effect!
await new Promise(resolve => setTimeout(resolve, 500)); // Wait 0.5s for dramatic effect

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd remove this, because the real API call adds enough drama. 😄

Comment thread src/api/rockets/index.ts
const data: JsonResponse = JSON.parse(await getRockets());
//I do not believe parsing an axios response is necessary so I removed it.
//Had to troubleshoot for a few minutes why data was not passing through, the culprit was the parse function.
const data: JsonResponse = await getRockets();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What happens if the API service returns an error? (Like when the site is down.)

@elliotgonzalez123

elliotgonzalez123 commented Mar 19, 2020 via email

Copy link
Copy Markdown
Author

@elliotgonzalez123

Copy link
Copy Markdown
Author

Hey John,

I accidentally created a new pull request with the requested changes. Sorry about that. All of my changes are in the other request. Thanks.

-Elliot

This branch has not been deployed

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

2 participants