-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GUILD-2017] - Requirement types (#25)
* test improvements * update @guildxyz/types * fix some tests * use randomly generated wallets * use proper update type * upgrade @guildxyz/types * 2.3.0
- Loading branch information
Showing
19 changed files
with
464 additions
and
483 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,64 @@ | ||
import { Guild } from "@guildxyz/types"; | ||
import { Wallet } from "ethers"; | ||
import { assert, describe, expect, it } from "vitest"; | ||
import { createGuildClient } from "../../src"; | ||
import { GuildSDKValidationError } from "../../src/error"; | ||
import { createSigner } from "../../src/utils"; | ||
import { CLIENT, TEST_SIGNER, TEST_USER } from "../common"; | ||
import { createTestGuild, pick } from "../utils"; | ||
|
||
// TODO Create test guilds for these instead of using data like our-guild | ||
const createdGuild = await createTestGuild(); | ||
const createdGuild2 = await createTestGuild(); | ||
|
||
const TEST_WALLET_SIGNER = createSigner.fromEthersWallet( | ||
new Wallet(process.env.PRIVATE_KEY!) | ||
); | ||
|
||
const { guild } = createGuildClient("vitest"); | ||
|
||
describe.concurrent("Guild client", () => { | ||
describe("Guild client", () => { | ||
it("Can get a guild by id", async () => { | ||
const response = await guild.get(1985); | ||
const response = await CLIENT.guild.get(createdGuild.id); | ||
|
||
expect(response).toMatchObject({ | ||
urlName: "our-guild", | ||
name: "Our Guild", | ||
} satisfies Partial<Guild>); | ||
expect(response).toMatchObject(pick(createdGuild, ["id", "urlName"])); | ||
}); | ||
|
||
it("Can get multiple guilds by ids", async () => { | ||
const response = await guild.getMany([1985, 20111]); | ||
|
||
expect(response).toMatchObject([ | ||
{ | ||
urlName: "our-guild", | ||
name: "Our Guild", | ||
} satisfies Partial<Guild>, | ||
{ | ||
urlName: "buildonbase", | ||
name: "Base Guild", | ||
} satisfies Partial<Guild>, | ||
const response = await CLIENT.guild.getMany([ | ||
createdGuild.id, | ||
createdGuild2.id, | ||
]); | ||
}); | ||
|
||
it("Can get multiple guilds with pagination", async () => { | ||
const [ | ||
[firstGuild, , , , fifthGuild], | ||
[fifthGuildWithPagination], | ||
[firstGuildWithPagination], | ||
] = await Promise.all([ | ||
guild.search({ limit: 5, offset: 0 }), | ||
guild.search({ | ||
limit: 1, | ||
offset: 4, | ||
}), | ||
guild.search({ | ||
limit: 1, | ||
offset: 0, | ||
}), | ||
expect(response).toMatchObject([ | ||
pick(createdGuild, ["id", "urlName"]), | ||
pick(createdGuild2, ["id", "urlName"]), | ||
]); | ||
|
||
expect(fifthGuildWithPagination.id).toEqual(fifthGuild.id); | ||
expect(firstGuildWithPagination.id).toEqual(firstGuild.id); | ||
}); | ||
|
||
it("Can get guild members", async () => { | ||
const numberOfPublicRoles = await guild.role | ||
.getAll(1985) | ||
.then((res) => res.length); | ||
const response = await CLIENT.guild.getMembers(createdGuild.id); | ||
|
||
const response = await guild.getMembers(1985); | ||
|
||
expect(response).toHaveLength(numberOfPublicRoles); | ||
expect(response).toHaveLength(1); | ||
}); | ||
|
||
it("Can get user membership for guild", async () => { | ||
const numberOfPublicRoles = await guild.role | ||
.getAll(1985) | ||
.then((res) => res.length); | ||
|
||
const response = await guild.getUserMemberships(1985, 4226297); | ||
const response = await CLIENT.guild.getUserMemberships( | ||
createdGuild.id, | ||
TEST_USER.id | ||
); | ||
|
||
expect(response).toHaveLength(numberOfPublicRoles); | ||
expect(response).toHaveLength(1); | ||
}); | ||
|
||
describe("guild create - update - delete", () => { | ||
let createdGuildId: number; | ||
|
||
it("Can create guild", async () => { | ||
const response = await guild.create( | ||
{ | ||
name: "SDK Test Guild", | ||
urlName: "sdk-test-guild", | ||
roles: [ | ||
{ | ||
name: "SDK Test Role", | ||
requirements: [{ type: "FREE" }], | ||
}, | ||
], | ||
}, | ||
TEST_WALLET_SIGNER | ||
); | ||
|
||
createdGuildId = response.id; | ||
|
||
expect(response).toMatchObject({ | ||
name: "SDK Test Guild", | ||
roles: [ | ||
{ | ||
name: "SDK Test Role", | ||
requirements: [{ type: "FREE" }], | ||
}, | ||
], | ||
}); | ||
expect(response.urlName.startsWith("sdk-test-guild")).toBeTruthy(); | ||
}); | ||
|
||
it("Can update guild", async () => { | ||
try { | ||
await guild.update(createdGuildId, {}, TEST_WALLET_SIGNER); | ||
assert(false); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(GuildSDKValidationError); | ||
} | ||
|
||
const updated = await guild.update( | ||
createdGuildId, | ||
{ description: "EDITED" }, | ||
TEST_WALLET_SIGNER | ||
); | ||
|
||
expect(updated.description).toMatchObject("EDITED"); | ||
}); | ||
|
||
it("Subsequent GET returns updated data", async () => { | ||
const fetchedGuild = await guild.get(createdGuildId); | ||
expect(fetchedGuild.description).toEqual("EDITED"); | ||
}); | ||
it("Can update guild", async () => { | ||
try { | ||
await CLIENT.guild.update(createdGuild.id, {}, TEST_SIGNER); | ||
assert(false); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(GuildSDKValidationError); | ||
} | ||
|
||
const updated = await CLIENT.guild.update( | ||
createdGuild.id, | ||
{ description: "EDITED" }, | ||
TEST_SIGNER | ||
); | ||
|
||
expect(updated.description).toMatchObject("EDITED"); | ||
}); | ||
|
||
it("Can delete guild", async () => { | ||
await guild.delete(createdGuildId, TEST_WALLET_SIGNER); | ||
}); | ||
it("Subsequent GET returns updated data", async () => { | ||
const fetchedGuild = await CLIENT.guild.get(createdGuild.id); | ||
expect(fetchedGuild.description).toEqual("EDITED"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.