From 03ee42e58f9050f9e7e03b83b4234db067db6de3 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 6 Nov 2024 16:43:29 -0600 Subject: [PATCH] Refactor tests with new type naming --- sdks/node-sdk/test/Client.test.ts | 47 ++++++++++-------------- sdks/node-sdk/test/Conversation.test.ts | 12 +++--- sdks/node-sdk/test/Conversations.test.ts | 15 +++----- sdks/node-sdk/test/helpers.ts | 4 +- 4 files changed, 33 insertions(+), 45 deletions(-) diff --git a/sdks/node-sdk/test/Client.test.ts b/sdks/node-sdk/test/Client.test.ts index aadb98b05..bee24fcf4 100644 --- a/sdks/node-sdk/test/Client.test.ts +++ b/sdks/node-sdk/test/Client.test.ts @@ -1,7 +1,7 @@ import { - NapiConsentEntityType, - NapiConsentState, - NapiSignatureRequestType, + ConsentEntityType, + ConsentState, + SignatureRequestType, } from "@xmtp/node-bindings"; import { v4 } from "uuid"; import { toBytes } from "viem"; @@ -116,11 +116,8 @@ describe("Client", () => { message: signatureText!, }); - client.addSignature(NapiSignatureRequestType.AddWallet, toBytes(signature)); - client.addSignature( - NapiSignatureRequestType.AddWallet, - toBytes(signature2), - ); + client.addSignature(SignatureRequestType.AddWallet, toBytes(signature)); + client.addSignature(SignatureRequestType.AddWallet, toBytes(signature2)); await client.applySignatures(); const inboxState = await client.inboxState(); expect(inboxState.accountAddresses.length).toEqual(2); @@ -150,11 +147,8 @@ describe("Client", () => { message: signatureText!, }); - client.addSignature(NapiSignatureRequestType.AddWallet, toBytes(signature)); - client.addSignature( - NapiSignatureRequestType.AddWallet, - toBytes(signature2), - ); + client.addSignature(SignatureRequestType.AddWallet, toBytes(signature)); + client.addSignature(SignatureRequestType.AddWallet, toBytes(signature2)); await client.applySignatures(); const signatureText2 = await client.revokeWalletSignatureText( @@ -167,10 +161,7 @@ describe("Client", () => { message: signatureText2!, }); - client.addSignature( - NapiSignatureRequestType.RevokeWallet, - toBytes(signature3), - ); + client.addSignature(SignatureRequestType.RevokeWallet, toBytes(signature3)); await client.applySignatures(); const inboxState = await client.inboxState(); expect(inboxState.accountAddresses).toEqual([ @@ -204,7 +195,7 @@ describe("Client", () => { }); client3.addSignature( - NapiSignatureRequestType.RevokeInstallations, + SignatureRequestType.RevokeInstallations, toBytes(signature), ); await client3.applySignatures(); @@ -229,27 +220,27 @@ describe("Client", () => { expect(group2).not.toBeNull(); expect( - await client2.getConsentState(NapiConsentEntityType.GroupId, group2!.id), - ).toBe(NapiConsentState.Unknown); + await client2.getConsentState(ConsentEntityType.GroupId, group2!.id), + ).toBe(ConsentState.Unknown); await client2.setConsentStates([ { - entityType: NapiConsentEntityType.GroupId, + entityType: ConsentEntityType.GroupId, entity: group2!.id, - state: NapiConsentState.Allowed, + state: ConsentState.Allowed, }, ]); expect( - await client2.getConsentState(NapiConsentEntityType.GroupId, group2!.id), - ).toBe(NapiConsentState.Allowed); + await client2.getConsentState(ConsentEntityType.GroupId, group2!.id), + ).toBe(ConsentState.Allowed); - expect(group2!.consentState).toBe(NapiConsentState.Allowed); + expect(group2!.consentState).toBe(ConsentState.Allowed); - group2!.updateConsentState(NapiConsentState.Denied); + group2!.updateConsentState(ConsentState.Denied); expect( - await client2.getConsentState(NapiConsentEntityType.GroupId, group2!.id), - ).toBe(NapiConsentState.Denied); + await client2.getConsentState(ConsentEntityType.GroupId, group2!.id), + ).toBe(ConsentState.Denied); }); }); diff --git a/sdks/node-sdk/test/Conversation.test.ts b/sdks/node-sdk/test/Conversation.test.ts index b8d628ef8..0002e2319 100644 --- a/sdks/node-sdk/test/Conversation.test.ts +++ b/sdks/node-sdk/test/Conversation.test.ts @@ -1,4 +1,4 @@ -import { NapiConsentState } from "@xmtp/node-bindings"; +import { ConsentState } from "@xmtp/node-bindings"; import { describe, expect, it } from "vitest"; import { ContentTypeTest, @@ -323,7 +323,7 @@ describe("Conversation", () => { const streamedMessages: string[] = []; const stream = conversation2[0].stream((_, message) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - streamedMessages.push(message.content); + streamedMessages.push(message!.content); }); await conversation.send("gm"); @@ -414,15 +414,15 @@ describe("Conversation", () => { await client2.conversations.sync(); const group2 = client2.conversations.getConversationById(group.id); expect(group2).toBeDefined(); - expect(group2!.consentState).toBe(NapiConsentState.Unknown); + expect(group2!.consentState).toBe(ConsentState.Unknown); await group2!.send("gm!"); - expect(group2!.consentState).toBe(NapiConsentState.Allowed); + expect(group2!.consentState).toBe(ConsentState.Allowed); await client3.conversations.sync(); const dmGroup2 = client3.conversations.getConversationById(dmGroup.id); expect(dmGroup2).toBeDefined(); - expect(dmGroup2!.consentState).toBe(NapiConsentState.Unknown); + expect(dmGroup2!.consentState).toBe(ConsentState.Unknown); await dmGroup2!.send("gm!"); - expect(dmGroup2!.consentState).toBe(NapiConsentState.Allowed); + expect(dmGroup2!.consentState).toBe(ConsentState.Allowed); }); }); diff --git a/sdks/node-sdk/test/Conversations.test.ts b/sdks/node-sdk/test/Conversations.test.ts index b041d8bd7..a6dc93df7 100644 --- a/sdks/node-sdk/test/Conversations.test.ts +++ b/sdks/node-sdk/test/Conversations.test.ts @@ -1,7 +1,4 @@ -import { - NapiConsentState, - NapiGroupPermissionsOptions, -} from "@xmtp/node-bindings"; +import { ConsentState, GroupPermissionsOptions } from "@xmtp/node-bindings"; import { describe, expect, it } from "vitest"; import { createRegisteredClient, createUser } from "@test/helpers"; @@ -33,7 +30,7 @@ describe("Conversations", () => { expect(conversation.isActive).toBe(true); expect(conversation.name).toBe(""); expect(conversation.permissions.policyType).toBe( - NapiGroupPermissionsOptions.AllMembers, + GroupPermissionsOptions.AllMembers, ); expect(conversation.permissions.policySet).toEqual({ addMemberPolicy: 0, @@ -87,7 +84,7 @@ describe("Conversations", () => { expect(group.isActive).toBe(true); expect(group.name).toBe(""); expect(group.permissions.policyType).toBe( - NapiGroupPermissionsOptions.CustomPolicy, + GroupPermissionsOptions.CustomPolicy, ); expect(group.permissions.policySet).toEqual({ addAdminPolicy: 1, @@ -109,7 +106,7 @@ describe("Conversations", () => { expect(group.metadata.conversationType).toBe("dm"); expect(group.metadata.creatorInboxId).toBe(client1.inboxId); - expect(group.consentState).toBe(NapiConsentState.Allowed); + expect(group.consentState).toBe(ConsentState.Allowed); const group1 = await client1.conversations.list(); expect(group1.length).toBe(1); @@ -214,14 +211,14 @@ describe("Conversations", () => { const groupWithPermissions = await client1.conversations.newConversation( [user4.account.address], { - permissions: NapiGroupPermissionsOptions.AdminOnly, + permissions: GroupPermissionsOptions.AdminOnly, }, ); expect(groupWithPermissions).toBeDefined(); expect(groupWithPermissions.name).toBe(""); expect(groupWithPermissions.imageUrl).toBe(""); expect(groupWithPermissions.permissions.policyType).toBe( - NapiGroupPermissionsOptions.AdminOnly, + GroupPermissionsOptions.AdminOnly, ); expect(groupWithPermissions.permissions.policySet).toEqual({ diff --git a/sdks/node-sdk/test/helpers.ts b/sdks/node-sdk/test/helpers.ts index fb55a1986..4b306a5ce 100644 --- a/sdks/node-sdk/test/helpers.ts +++ b/sdks/node-sdk/test/helpers.ts @@ -5,7 +5,7 @@ import { type ContentCodec, type EncodedContent, } from "@xmtp/content-type-primitives"; -import { NapiSignatureRequestType } from "@xmtp/node-bindings"; +import { SignatureRequestType } from "@xmtp/node-bindings"; import { v4 } from "uuid"; import { createWalletClient, http, toBytes } from "viem"; import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; @@ -61,7 +61,7 @@ export const createRegisteredClient = async ( if (!client.isRegistered) { const signature = await getSignature(client, user); if (signature) { - client.addSignature(NapiSignatureRequestType.CreateInbox, signature); + client.addSignature(SignatureRequestType.CreateInbox, signature); } await client.registerIdentity(); }