Skip to content
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

upcoming: [M3-7414] - Add mocks and update queries for new Parent/Child endpoints #9977

Merged
merged 7 commits into from
Dec 11, 2023

Conversation

mjac0bs
Copy link
Contributor

@mjac0bs mjac0bs commented Dec 7, 2023

Description 📝

This PR adds Mock Service Worker (MSW) endpoints for all new "Parent/Child" API calls. (Updates to all existing endpoints were previously done in #9942.) These changes will enable us to mock the Parent/Child API interactions, ensuring our development remains unimpeded and independent of ongoing API changes.

Changes 🔄

  • Added endpoints to the MSW for new Parent/Child endpoints.
  • Updated the queries for useChildAccounts and useChildAccount to allow an unrestricted parent account to be able to reach these endpoints. (They will have child_account_access by default, but we can't check grants on an unrestricted user, which was relied upon in the initial implementation of the queries.)

Preview 📷

Screenshot 2023-12-08 at 10 05 53 AM Screenshot 2023-12-08 at 10 06 19 AM
Screenshot 2023-12-08 at 10 05 45 AM Screenshot 2023-12-08 at 10 06 04 AM
Screenshot 2023-12-08 at 10 08 04 AM Screenshot 2023-12-08 at 10 08 57 AM

How to test 🧪

Prerequisites

(How to setup test environment)

  • Check out this PR and add a new REACT_APP_PROXY_PAT to your .env with any token to test. We'll need to store a mock "proxy" token to log into a child account somewhere until the API returns it.
  • Start the dev server: yarn dev.
  • In dev tools:
    • Turn on the MSW.
    • Make sure the Parent/Child feature flag is on.

Verification steps

(How to verify changes)

  const { data: childAccounts } = useChildAccounts({});
  const { data: childAccount } = useChildAccount({ euuid: '1' });
  const {
    mutateAsync: fetchProxyToken,
  } = useCreateChildAccountPersonalAccessTokenMutation({ euuid: '1' });

  fetchProxyToken({ euuid: '1' })
      .then((data) => {
        console.log({ data });
      })
  • To test the mocked queries, add the code to a component (UserMenu makes sense for our purposes) and verify in the dev console log and/or through the network request and response payload that the mocked requests to GET /account/child-accounts, GET /account/child-accounts/<euuid>, and POST /account/child-accounts/<euuid>/token are all executing and returning the expected data.

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@mjac0bs mjac0bs self-assigned this Dec 7, 2023
@mjac0bs mjac0bs changed the title upcoming: [M3-7414] - Add mock data for Parent/Child account switching upcoming: [M3-7414] - Add mocks and update queries for new Parent/Child endpoints Dec 8, 2023
Comment on lines -63 to +68
Boolean(grants?.global?.child_account_access) || hasExplicitAuthToken,
(Boolean(user?.user_type === 'parent') && !profile?.restricted) ||
Boolean(grants?.global?.child_account_access) ||
hasExplicitAuthToken,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change and the change in the query below allows an unrestricted parent user (who cannot call useGrants) to access the endpoint.

@mjac0bs mjac0bs marked this pull request as ready for review December 8, 2023 18:15
@mjac0bs mjac0bs requested a review from a team as a code owner December 8, 2023 18:15
@mjac0bs mjac0bs requested review from abailly-akamai and coliu-akamai and removed request for a team December 8, 2023 18:15
@mjac0bs mjac0bs force-pushed the M3-7414-add-parent-child-mocks branch from 9e2ab75 to e270bf4 Compare December 8, 2023 19:57
Copy link

github-actions bot commented Dec 8, 2023

Coverage Report:
Base Coverage: 86.51%
Current Coverage: 86.51%

Copy link
Contributor

@jaalah-akamai jaalah-akamai left a comment

Choose a reason for hiding this comment

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

Changes look good

@jaalah-akamai jaalah-akamai added the Add'tl Approval Needed Waiting on another approval! label Dec 11, 2023
@tyler-akamai
Copy link
Contributor

tyler-akamai commented Dec 11, 2023

Verified the following returns the mocked data

  • GET /account/child-accounts
  • GET /account/child-accounts/<euuid>
  • POST /account/child-accounts/<euuid>/token

@tyler-akamai
Copy link
Contributor

LGTM, great work

Screenshot 2023-12-11 at 3 23 54 PM

@mjac0bs mjac0bs added Approved Multiple approvals and ready to merge! and removed Add'tl Approval Needed Waiting on another approval! labels Dec 11, 2023
@mjac0bs
Copy link
Contributor Author

mjac0bs commented Dec 11, 2023

Merging this now. The only CI test failure was on rebuild-linode.spec.ts and was unrelated. (And that test passes locally.)
Screenshot 2023-12-11 at 12 41 30 PM

@mjac0bs mjac0bs merged commit 914d226 into linode:develop Dec 11, 2023
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge! Parent / Child Account
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants