diff --git a/embed/__tests__/index.test.ts b/embed/__tests__/index.test.ts index fc9d849f94..eaf2fb8f82 100644 --- a/embed/__tests__/index.test.ts +++ b/embed/__tests__/index.test.ts @@ -3,7 +3,11 @@ import request from "supertest"; import { Response, Request } from "express"; import { apiKeyRateLimit, keyGenerator } from "../src/rate-limiter"; -import { AutoVerificationResponseBodyType, AutoVerificationRequestBodyType } from "../src/handlers"; +import { + AutoVerificationResponseBodyType, + AutoVerificationRequestBodyType, + autoVerificationHandler, +} from "../src/handlers"; import { ParamsDictionary } from "express-serve-static-core"; import { PassportScore } from "@gitcoin/passport-identity"; @@ -59,7 +63,7 @@ beforeEach(() => { jest.clearAllMocks(); }); -describe("POST /embed/verify", function () { +describe("autoVerificationHandler", function () { it("handles valid verify requests", async () => { // as each signature is unique, each request results in unique output const payload = { @@ -76,6 +80,7 @@ describe("POST /embed/verify", function () { expect(apiKeyRateLimit as jest.Mock).toHaveBeenCalledTimes(1); expect(keyGenerator as jest.Mock).toHaveBeenCalledTimes(1); + expect(autoVerificationHandler as jest.Mock).toHaveBeenCalledTimes(1); expect(verifyRequest.status).toBe(200); expect(verifyRequest.body).toStrictEqual(mockedScore); }); diff --git a/embed/src/handlers.ts b/embed/src/handlers.ts index 319afc8d3d..43f4edb51d 100644 --- a/embed/src/handlers.ts +++ b/embed/src/handlers.ts @@ -23,6 +23,7 @@ export type PassportProviderPoints = { export type AutoVerificationRequestBodyType = { address: string; scorerId: string; + credentialIds?: []; }; type AutoVerificationFields = AutoVerificationRequestBodyType; @@ -63,6 +64,7 @@ export const addStampsAndGetScore = async ({ scorerId, stamps, }: AutoVerificationFields & { stamps: VerifiableCredential[] }): Promise => { + console.log("geri ---- addStampsAndGetScore"); try { const scorerResponse: { data?: { @@ -81,8 +83,10 @@ export const addStampsAndGetScore = async ({ } ); + console.log("geri ---- scorerResponse", scorerResponse); return scorerResponse.data?.score; } catch (error) { + console.log("geri ---- scorerResponse error", error); handleAxiosError(error, "Scorer Embed API", EmbedAxiosError, [apiKey]); } }; @@ -92,13 +96,13 @@ export const autoVerificationHandler = async ( res: Response ): Promise => { try { - const { address, scorerId } = req.body; + const { address, scorerId, credentialIds } = req.body; if (!isAddress(address)) { return void errorRes(res, "Invalid address", 400); } - const stamps = await autoVerifyStamps({ address, scorerId }); + const stamps = await autoVerifyStamps({ address, scorerId, credentialIds }); const score = await addStampsAndGetScore({ address, scorerId, stamps }); @@ -108,6 +112,7 @@ export const autoVerificationHandler = async ( if (error instanceof EmbedAxiosError) { return void errorRes(res, error.message, error.code); } + const message = addErrorDetailsToMessage("Unexpected error when processing request", error); return void errorRes(res, message, 500); }