Skip to content

Commit

Permalink
feat: start identity verification without authenticating (#4133)
Browse files Browse the repository at this point in the history
* startIdentityVerificationMutation does not require auth

* remove identityVerification by id loader with auth

* adjust tests

* add back the guard but return null

* remove unecessary loader check
  • Loading branch information
ovasdi authored Jun 10, 2022
1 parent fb379b0 commit 1805d43
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
13 changes: 0 additions & 13 deletions src/lib/loaders/loaders_with_authentication/gravity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import factories from "../api"
import trackedEntityLoaderFactory from "lib/loaders/loaders_with_authentication/tracked_entity"

export type StartIdentityVerificationGravityOutput = {
identity_verification_id: string
identity_verification_flow_url: string
}

export default (accessToken, userID, opts) => {
const gravityAccessTokenLoader = () => Promise.resolve(accessToken)
const { gravityLoaderWithAuthenticationFactory } = factories(opts)
Expand All @@ -14,9 +9,6 @@ export default (accessToken, userID, opts) => {
)

return {
identityVerificationLoader: gravityLoader(
(id) => `identity_verification/${id}`
),
identityVerificationsLoader: gravityLoader(
"identity_verifications",
{},
Expand Down Expand Up @@ -354,11 +346,6 @@ export default (accessToken, userID, opts) => {
),
sendFeedbackLoader: gravityLoader("feedback", {}, { method: "POST" }),
showLoader: gravityLoader((id) => `show/${id}`),
startIdentityVerificationLoader: gravityLoader(
(id) => `identity_verification/${id}/start`,
{},
{ method: "PUT" }
),
suggestedArtistsLoader: gravityLoader(
"me/suggested/artists",
{},
Expand Down
10 changes: 10 additions & 0 deletions src/lib/loaders/loaders_without_authentication/gravity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import gravity from "lib/apis/gravity"
import { createBatchLoaders } from "../batchLoader"
import { searchLoader } from "../searchLoader"

export type StartIdentityVerificationGravityOutput = {
identity_verification_id: string
identity_verification_flow_url: string
}

export default (opts) => {
const { gravityLoaderWithoutAuthenticationFactory } = factories(opts)
const gravityLoader = gravityLoaderWithoutAuthenticationFactory
Expand Down Expand Up @@ -244,6 +249,11 @@ export default (opts) => {
{},
{ headers: true }
),
startIdentityVerificationLoader: gravityLoader(
(id) => `identity_verification/${id}/start`,
{},
{ method: "PUT" }
),
staticContentLoader: gravityLoader((id) => `page/${id}`),
systemTimeLoader: gravityUncachedLoader("system/time", null),
tagLoader: gravityLoader((id) => `tag/${id}`),
Expand Down
20 changes: 7 additions & 13 deletions src/schema/v2/__tests__/startIdentityVerificationMutation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { runQuery, runAuthenticatedQuery } from "schema/v2/test/utils"
import { StartIdentityVerificationGravityOutput } from "lib/loaders/loaders_with_authentication/gravity"
import { runQuery } from "schema/v2/test/utils"
import { StartIdentityVerificationGravityOutput } from "lib/loaders/loaders_without_authentication/gravity"

const mutation = `
mutation {
Expand All @@ -22,12 +22,6 @@ mutation {
`

describe("starting an identity verification", () => {
it("requires an access token", async () => {
await expect(runQuery(mutation)).rejects.toThrow(
"You need to be signed in to perform this action"
)
})

it("returns the given identity verification ID and flow URL from Gravity", async () => {
const gravityResponse: StartIdentityVerificationGravityOutput = {
identity_verification_id: "idv-123",
Expand All @@ -38,7 +32,7 @@ describe("starting an identity verification", () => {
startIdentityVerificationLoader: () => Promise.resolve(gravityResponse),
}

const response = await runAuthenticatedQuery(mutation, context)
const response = await runQuery(mutation, context)

expect(response).toEqual({
startIdentityVerification: {
Expand All @@ -61,7 +55,7 @@ describe("starting an identity verification", () => {
),
}

const response = await runAuthenticatedQuery(mutation, errorRootValue)
const response = await runQuery(mutation, errorRootValue)

expect(response).toEqual({
startIdentityVerification: {
Expand All @@ -83,8 +77,8 @@ describe("starting an identity verification", () => {
},
}

await expect(
runAuthenticatedQuery(mutation, errorRootValue)
).rejects.toThrow("ETIMEOUT service unreachable")
await expect(runQuery(mutation, errorRootValue)).rejects.toThrow(
"ETIMEOUT service unreachable"
)
})
})
4 changes: 0 additions & 4 deletions src/schema/v2/startIdentityVerificationMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ export const startIdentityVerificationMutation = mutationWithClientMutationId<
{ identityVerificationId },
{ startIdentityVerificationLoader }
) => {
if (!startIdentityVerificationLoader) {
throw new Error("You need to be signed in to perform this action")
}

return startIdentityVerificationLoader(identityVerificationId).catch(
(error) => {
const formattedErr = formatGravityError(error)
Expand Down

0 comments on commit 1805d43

Please sign in to comment.