Skip to content

Commit

Permalink
fix: test case for handling unknown user data type
Browse files Browse the repository at this point in the history
  • Loading branch information
stephancill committed Oct 23, 2024
1 parent 91bc168 commit 3545d54
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions packages/frames.js/src/getUserDataForFid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,57 @@ describe("getUserDataForFid", () => {
'Failed to parse response body as JSON because server hub returned response with status "504" and body "Gateway Timeout"'
);
});

it("warns if message could not be parsed", async () => {
nock(DEFAULT_HUB_API_URL)
.get("/v1/userDataByFid?fid=1214")
.reply(200, {
messages: [
{
data: {
type: "MESSAGE_TYPE_USER_DATA_ADD",
fid: 1214,
timestamp: 69403426,
network: "FARCASTER_NETWORK_MAINNET",
userDataBody: {
type: "USER_DATA_TYPE_SOMETHING_UNKNOWN",
value:
"https://lh3.googleusercontent.com/-S5cdhOpZtJ_Qzg9iPWELEsRTkIsZ7qGYmVlwEORgFB00WWAtZGefRnS4Bjcz5ah40WVOOWeYfU5pP9Eekikb3cLMW2mZQOMQHlWhg",
},
},
hash: "0x465e44c9d8b4f6189d40b79029168a1dc0b50ea5",
hashScheme: "HASH_SCHEME_BLAKE3",
signature:
"x4J7Lo4FM7wutYYomV7ItFSOlo3Rca4s+BQ5rQK0dvRpIrsCCX7BU5fnkX3UfseXTyh4kJOVYmeEhLeeA27oAw==",
signatureScheme: "SIGNATURE_SCHEME_ED25519",
signer:
"0xf23a5c7b9f067c621a989a585b78daf7b2a9debe9d54325ef95b0878f44204c6",
},
],
});

const consoleWarnSpy = jest
.spyOn(console, "warn")
.mockImplementation(() => {});

const result = await getUserDataForFid({ fid: 1214 });

expect(consoleWarnSpy).toHaveBeenCalled();
expect(consoleWarnSpy).toHaveBeenCalledWith(
"Failed to parse user data message for fid 1214",
expect.any(Object),
expect.any(Error)
);

expect(result).toBeDefined();
if (!result) {
throw new Error("Result is null");
}

const allValuesUndefined = Object.values(result).every(
(value) => value === undefined
);

expect(allValuesUndefined).toBe(true);
});
});

0 comments on commit 3545d54

Please sign in to comment.