Skip to content

Commit

Permalink
Refactor tests with new type naming
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Nov 6, 2024
1 parent a241007 commit 03ee42e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 45 deletions.
47 changes: 19 additions & 28 deletions sdks/node-sdk/test/Client.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
NapiConsentEntityType,
NapiConsentState,
NapiSignatureRequestType,
ConsentEntityType,
ConsentState,
SignatureRequestType,
} from "@xmtp/node-bindings";
import { v4 } from "uuid";
import { toBytes } from "viem";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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([
Expand Down Expand Up @@ -204,7 +195,7 @@ describe("Client", () => {
});

client3.addSignature(
NapiSignatureRequestType.RevokeInstallations,
SignatureRequestType.RevokeInstallations,
toBytes(signature),
);
await client3.applySignatures();
Expand All @@ -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);
});
});
12 changes: 6 additions & 6 deletions sdks/node-sdk/test/Conversation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NapiConsentState } from "@xmtp/node-bindings";
import { ConsentState } from "@xmtp/node-bindings";
import { describe, expect, it } from "vitest";
import {
ContentTypeTest,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
});
});
15 changes: 6 additions & 9 deletions sdks/node-sdk/test/Conversations.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions sdks/node-sdk/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 03ee42e

Please sign in to comment.