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

chore: Drop adminClient (1/2) #2356

Merged
merged 10 commits into from
Nov 3, 2023
Merged

chore: Drop adminClient (1/2) #2356

merged 10 commits into from
Nov 3, 2023

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Nov 1, 2023

What does this PR do?

Principles

  • Queries should be typed (by default planx-core is returning an unknown otherwise). For simplicity I've just used the mutation / query name as the interface name. If this isn't clear / meaningful I can append a Query / Mutation suffix.

  • Where possible, use queries as the place where we convert snake_case (from the db) to camelCase (in the application). This means our interfaces and types are all camelCase as expected. This has meant cascading (noisy) changes to code and tests but it seemed worthwhile over introducing more snake_case properties to types.

  • Allow $api client for side-effects triggered by permission-scoped users (such as writing audit logs). The alternative here would be to increase public client scope and add backend-only mutations - see previous thoughts on this here.

Copy link

github-actions bot commented Nov 1, 2023

Removed vultr server and associated DNS entries

@DafyddLlyr DafyddLlyr force-pushed the dp/drop-admin-client-1 branch 4 times, most recently from c1746ca to 353008e Compare November 1, 2023 17:08
@DafyddLlyr DafyddLlyr force-pushed the dp/drop-admin-client-1 branch from 353008e to 6ed792a Compare November 1, 2023 17:49
Copy link

github-actions bot commented Nov 2, 2023

🤖 Hasura Change Summary compared a subset of table metadata including permissions:

Updated Tables (1)

  • public.reconciliation_requests permissions:

    insert select update delete
    api
    5 added column permissions
    insert select update
    api ➕ created_at
    ➕ id
    ➕ message
    ➕ response
    ➕ session_id

@@ -1116,6 +1116,16 @@
- message
- session_id
- created_at
select_permissions:
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 was required to give the API role access to the insert_reconciliation_requests_one mutation.

insert_<object>_one will only be available if you have select permissions on the table, as it returns the inserted row

Docs: https://hasura.io/docs/latest/mutations/postgres/insert/#insert-a-single-object

Comment on lines 16 to 29
jest.mock("@opensystemslab/planx-core", () => {
const actualCoreDomainClient = jest.requireActual(
"@opensystemslab/planx-core",
).CoreDomainClient;

return {
CoreDomainClient: jest.fn().mockImplementation(() => ({
formatRawProjectTypes: () => mockFormatRawProjectTypes(),
})),
CoreDomainClient: class extends actualCoreDomainClient {
constructor() {
super();
this.formatRawProjectTypes = () => mockFormatRawProjectTypes();
}
},
};
});
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Nov 3, 2023

Choose a reason for hiding this comment

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

What's going on here?

CoreDomainClient client is being mocked so that we can control and modify the behaviour of formatRawProjectTypes() and test it.

However, we want to retain the behaviour of CoreDomainClient.client so that real GraphQL queries get made so that graphql-query-test-mock is able to catch and mock these calls. To do this we can use jest.requireActual to maintain this behaviour.

I feel like there's possibly a few more elegant options here - I'd like to revisit this.

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 structure is repeated a few times throughout this PR. I spent a good bit of time attempting to generalise it so that we could import it with an interface similar to -

function mockCoreDomainClient(customMocks = {}) {
   const actualCoreDomainClient = jest.requireActual(
    "@opensystemslab/planx-core",
  ).CoreDomainClient;

  return {
    CoreDomainClient: class extends actualCoreDomainClient {
      constructor() {
        super();
        Object.assign(this, customMocks)
      }
    }
  }
}

...

mockCoreDomainClient({
  formatRawProjectTypes: () => mockFormatRawProjectTypes(),
});

Tried a few variations without much success - I suspect the problem is related to how Jest is hoisting mocks (through the jest.mock("@opensystemslab/planx-core") notation). I wanted to just move on as opposed to losing more time here so I'll open a GitHub issue describing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue logged here - #2404

@DafyddLlyr DafyddLlyr requested a review from a team November 3, 2023 12:34
@DafyddLlyr DafyddLlyr marked this pull request as ready for review November 3, 2023 12:35
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Thanks for following through with all these updates and thorough explanations of how you've set up mocks here!

Left a few naming suggestions for clarity, but overall looks good 👍

api.planx.uk/inviteToPay/createPaymentSendEvents.test.ts Outdated Show resolved Hide resolved
api.planx.uk/saveAndReturn/resumeApplication.ts Outdated Show resolved Hide resolved
api.planx.uk/saveAndReturn/resumeApplication.ts Outdated Show resolved Hide resolved
* feat: Analytics

* feat: Session summary

* feat: Publish

* feat: Move flow

* feat: Find and replace

* feat: getFlowData()

* feat: insertFlow()

* feat: getMostRecentPublishedFlow()

* chore: Drop unused function

* feat: Payment status

* feat: Payment requests

* feat: Operations

* chore: Drop adminGraphQLClient

* chore: Linting

* fix: PR comments
@DafyddLlyr DafyddLlyr merged commit f896564 into main Nov 3, 2023
10 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/drop-admin-client-1 branch November 3, 2023 18:02
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