diff --git a/tests/api/disputes/disputes.post.spec.ts b/tests/api/disputes/disputes.post.spec.ts index b454018..4919c90 100644 --- a/tests/api/disputes/disputes.post.spec.ts +++ b/tests/api/disputes/disputes.post.spec.ts @@ -147,6 +147,7 @@ test.describe("List Disputes @Disputes", async () => { request, disputes, }) => { + const filterEmptyData = disputes.filter((d) => d.currentTag); const whereParams = [ { where: { @@ -163,7 +164,9 @@ test.describe("List Disputes @Disputes", async () => { }, { where: { - currentTag: disputes[1].currentTag, + currentTag: filterEmptyData + ? filterEmptyData[0].currentTag + : disputes[0].currentTag, }, exists: true, }, @@ -222,10 +225,10 @@ test.describe("List Disputes @Disputes", async () => { expect(errors).toBeUndefined(); if (exists) { expect(data.length).toBeGreaterThan(0); - if (where.currentTag !== "") { - data.forEach((item: object) => { + if (where.currentTag?.trim() !== "") { + for (const item of data) { expect(item).toMatchObject(where); - }); + } } } else { expect(data.length).toBe(0); diff --git a/tests/api/royalties/royalties-payments.get.spec.ts b/tests/api/royalties/royalties-payments.get.spec.ts new file mode 100644 index 0000000..a289815 --- /dev/null +++ b/tests/api/royalties/royalties-payments.get.spec.ts @@ -0,0 +1,42 @@ +import { test, expect } from "../fixtures/base"; +import { ApiPrefix } from "../../constants"; + +const endpoint = ApiPrefix + "/royalties/payments"; + +test.describe("Get a RoyaltyPay @Royalties", () => { + test("Should return RoyaltyPay detail", async ({ + request, + royaltiesPayments, + }) => { + const params = [ + { royaltyPayId: royaltiesPayments[0].id, exists: true }, + { royaltyPayId: "0x55ffbb07777249999", exists: false }, + ]; + for (const { royaltyPayId, exists } of params) { + await test.step(`Query with royaltyPayId ${royaltyPayId}`, async () => { + const response = await request.get(endpoint + `/${royaltyPayId}`); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + if (exists) { + expect(data.id).toBe(royaltyPayId); + expect(typeof data.payerIpId).toBe("string"); + expect(typeof data.receiverIpId).toBe("string"); + expect(typeof data.sender).toBe("string"); + expect(typeof data.token).toBe("string"); + expect(typeof data.amount).toBe("string"); + expect(typeof data.blockNumber).toBe("string"); + expect(typeof data.blockTimestamp).toBe("string"); + } else { + expect(data).toBeNull(); + } + }); + } + }); + + test("Should return 404 for no royaltyPayId", async ({ request }) => { + const response = await request.get(endpoint); + expect(response.status()).toBe(404); + }); +}); diff --git a/tests/api/royalties/royalties-payments.post.spec.ts b/tests/api/royalties/royalties-payments.post.spec.ts new file mode 100644 index 0000000..16a1464 --- /dev/null +++ b/tests/api/royalties/royalties-payments.post.spec.ts @@ -0,0 +1,273 @@ +import { test, expect } from "../fixtures/base"; +import { ApiPrefix } from "../../constants"; + +const endpoint = ApiPrefix + "/royalties/payments"; + +test.describe("List RoyaltyPays @Royalties", () => { + test("Should return default Royalty Pays list", async ({ request }) => { + const response = await request.post(endpoint); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + expect(Array.isArray(data)).toBeTruthy(); + expect(data.length).toBeGreaterThan(0); + expect(typeof data[0].id).toBe("string"); + expect(typeof data[0].payerIpId).toBe("string"); + expect(typeof data[0].receiverIpId).toBe("string"); + expect(typeof data[0].sender).toBe("string"); + expect(typeof data[0].token).toBe("string"); + expect(typeof data[0].amount).toBe("string"); + expect(typeof data[0].blockNumber).toBe("string"); + expect(typeof data[0].blockTimestamp).toBe("string"); + }); + + const pageParams = [ + { pagination: { offset: 0, limit: 5 } }, + { pagination: { offset: 1, limit: 4 } }, + { pagination: { offset: 2, limit: 3 } }, + ]; + for (const { pagination } of pageParams) { + test(`Should return Royalty Pays list with pagination ${JSON.stringify( + pagination + )}`, async ({ request, royaltiesPayments }) => { + const payload = { + options: { pagination: pagination }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const offsetResponse = await request.post(endpoint, { + data: { options: { pagination: { limit: 30 } } }, + }); + const offsetJson = await offsetResponse.json(); + const firstItem = offsetJson.data[pagination.offset]; + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + expect(data.length).toBeLessThanOrEqual(pagination.limit); + if (pagination.offset < royaltiesPayments.length) { + expect(data[0]).toMatchObject(firstItem); + } + }); + } + + const orderParams = [ + { orderBy: "id", orderDirection: "desc" }, + { orderBy: "id", orderDirection: "asc" }, + { orderBy: "payerIpId", orderDirection: "desc" }, + { orderBy: "payerIpId", orderDirection: "asc" }, + { orderBy: "receiverIpId", orderDirection: "desc" }, + { orderBy: "receiverIpId", orderDirection: "asc" }, + { orderBy: "sender", orderDirection: "desc" }, + { orderBy: "sender", orderDirection: "asc" }, + { orderBy: "token", orderDirection: "desc" }, + { orderBy: "token", orderDirection: "asc" }, + { orderBy: "amount", orderDirection: "desc" }, + { orderBy: "amount", orderDirection: "asc" }, + { orderBy: "blockNumber", orderDirection: "desc" }, + { orderBy: "blockNumber", orderDirection: "asc" }, + { orderBy: "blockTimestamp", orderDirection: "desc" }, + { orderBy: "blockTimestamp", orderDirection: "asc" }, + ]; + for (const { orderBy, orderDirection } of orderParams) { + test(`Should return Royalty Pays list with order by ${orderBy} and order direction ${orderDirection}`, async ({ + request, + }) => { + const payload = { + options: { orderBy, orderDirection }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + expect(data.length).toBeGreaterThan(0); + for (let i = 0; i < data.length - 1; i++) { + let item: string | number; + let nextItem: string | number; + if (orderBy === "amount") { + item = parseInt(data[i][orderBy]); + nextItem = parseInt(data[i + 1][orderBy]); + } else { + item = data[i][orderBy].trim() || "\uFFFF"; + nextItem = data[i + 1][orderBy].trim() || "\uFFFF"; + } + if (orderDirection === "asc") { + expect(item <= nextItem).toBeTruthy(); + } else { + expect(item >= nextItem).toBeTruthy(); + } + } + }); + } + + const pageAndOrderParams = [ + { + pagination: { offset: 0, limit: 5 }, + orderBy: "id", + orderDirection: "asc", + }, + { + pagination: { offset: 1, limit: 3 }, + orderBy: "payerIpId", + orderDirection: "desc", + }, + ]; + for (const { pagination, orderBy, orderDirection } of pageAndOrderParams) { + test(`Should return Royalty Pays list with pagination ${JSON.stringify( + pagination + )}, order by ${orderBy} and order direction ${orderDirection}`, async ({ + request, + royaltiesPayments, + }) => { + const payload = { + options: { pagination, orderBy, orderDirection }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + if (pagination.offset < royaltiesPayments.length) { + expect(data.length).toBeGreaterThan(0); + } + expect(data.length).toBeLessThanOrEqual(pagination.limit); + for (let i = 0; i < data.length - 1; i++) { + const item = data[i][orderBy].trim() || "\uFFFF"; + const nextItem = data[i + 1][orderBy].trim() || "\uFFFF"; + if (orderDirection === "asc") { + expect(item <= nextItem).toBeTruthy(); + } else { + expect(item >= nextItem).toBeTruthy(); + } + } + }); + } + + test("Should return Royalty Pays list with filter", async ({ + request, + royaltiesPayments, + }) => { + const whereParams = [ + { where: { payerIpId: royaltiesPayments[0].payerIpId }, exists: true }, + { + where: { payerIpId: "0x80ad6a261618b4fe3c2385f57e1ad7e614629999" }, + exists: false, + }, + { + where: { receiverIpId: royaltiesPayments[0].receiverIpId }, + exists: true, + }, + { + where: { receiverIpId: "0x80ad6a261618b4fe3c2385f57e1ad7e614629999" }, + exists: false, + }, + { where: { sender: royaltiesPayments[0].sender }, exists: true }, + { + where: { sender: "0xf398c12a45bc409b6c652e25bb0a3e7024929999" }, + exists: false, + }, + { where: { token: royaltiesPayments[0].token }, exists: true }, + { + where: { token: "0x857308523a01b430cb112400976b9fc4a6429999" }, + exists: false, + }, + { + where: { + payerIpId: royaltiesPayments[0].payerIpId, + token: royaltiesPayments[0].token, + }, + exists: true, + }, + { + where: { + receiverIpId: royaltiesPayments[0].receiverIpId, + sender: royaltiesPayments[0].sender, + }, + exists: true, + }, + ]; + for (const { where, exists } of whereParams) { + await test.step(`Query with ${JSON.stringify(where)}`, async () => { + const payload = { + options: { where }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + if (exists) { + expect(data.length).toBeGreaterThan(0); + for (const item of data) { + expect(item).toMatchObject(where); + } + } else { + expect(data.length).toBe(0); + } + }); + } + }); + + test("Should return Royalty Pays list with filter, order and pagination", async ({ + request, + royaltiesPayments, + }) => { + const params = [ + { + pagination: { offset: 0, limit: 5 }, + orderBy: "id", + orderDirection: "asc", + where: { payerIpId: royaltiesPayments[0].payerIpId }, + }, + { + pagination: { offset: 1, limit: 3 }, + orderBy: "payerIpId", + orderDirection: "desc", + where: { + payerIpId: royaltiesPayments[0].payerIpId, + token: royaltiesPayments[0].token, + }, + }, + ]; + for (const p of params) { + await test.step(`Query with ${JSON.stringify(p)}`, async () => { + const payload = { + options: { ...p }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + if (p.pagination.offset < royaltiesPayments.length) { + expect(data.length).toBeGreaterThan(0); + } + expect(data.length).toBeLessThanOrEqual(p.pagination.limit); + for (let i = 0; i < data.length - 1; i++) { + const item = data[i][p.orderBy].trim() || "\uFFFF"; + const nextItem = data[i + 1][p.orderBy].trim() || "\uFFFF"; + if (p.orderDirection === "asc") { + expect(item <= nextItem).toBeTruthy(); + } else { + expect(item >= nextItem).toBeTruthy(); + } + } + data.forEach((item: object) => { + expect(item).toMatchObject(p.where); + }); + }); + } + }); +}); diff --git a/tests/api/royalties/royalties-policies.get.spec.ts b/tests/api/royalties/royalties-policies.get.spec.ts new file mode 100644 index 0000000..9ad09b5 --- /dev/null +++ b/tests/api/royalties/royalties-policies.get.spec.ts @@ -0,0 +1,45 @@ +import { test, expect } from "../fixtures/base"; +import { ApiPrefix } from "../../constants"; + +const endpoint = ApiPrefix + "/royalties/policies"; + +test.describe("Get a Royalties Policy @Royalties", () => { + test("Should return Royalties Policy detail", async ({ + request, + royaltiesPolicies, + }) => { + const params = [ + { royaltyPolicyId: royaltiesPolicies[1].id, exists: true }, + { + royaltyPolicyId: "0x484c10779f9c5209b371afa029797e76129d9999", + exists: false, + }, + ]; + for (const { royaltyPolicyId, exists } of params) { + await test.step(`Query with royaltyPolicyId ${royaltyPolicyId}`, async () => { + const response = await request.get(endpoint + `/${royaltyPolicyId}`); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + if (exists) { + expect(data.id).toBe(royaltyPolicyId); + expect(typeof data.royaltyStack).toBe("string"); + expect(typeof data.splitClone).toBe("string"); + expect(typeof data.ancestorsVault).toBe("string"); + expect(Array.isArray(data.targetAncestors)).toBeTruthy(); + expect(Array.isArray(data.targetRoyaltyAmount)).toBeTruthy(); + expect(typeof data.blockNumber).toBe("string"); + expect(typeof data.blockTimestamp).toBe("string"); + } else { + expect(data).toBeNull(); + } + }); + } + }); + + test("Should return 404 for no royaltyPolicyId", async ({ request }) => { + const response = await request.get(endpoint); + expect(response.status()).toBe(404); + }); +}); diff --git a/tests/api/royalties/royalties-policies.post.spec.ts b/tests/api/royalties/royalties-policies.post.spec.ts new file mode 100644 index 0000000..61a0517 --- /dev/null +++ b/tests/api/royalties/royalties-policies.post.spec.ts @@ -0,0 +1,142 @@ +import { test, expect } from "../fixtures/base"; +import { ApiPrefix } from "../../constants"; + +const endpoint = ApiPrefix + "/royalties/policies"; + +test.describe("List RoyaltyPolicies @Royalties", () => { + test("Should return default Royalty Policies list", async ({ request }) => { + const response = await request.post(endpoint); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + expect(Array.isArray(data)).toBeTruthy(); + expect(data.length).toBeGreaterThan(0); + expect(typeof data[0].id).toBe("string"); + expect(typeof data[0].royaltyStack).toBe("string"); + expect(typeof data[0].splitClone).toBe("string"); + expect(typeof data[0].ancestorsVault).toBe("string"); + expect(Array.isArray(data[0].targetAncestors)).toBeTruthy(); + expect(Array.isArray(data[0].targetRoyaltyAmount)).toBeTruthy(); + expect(typeof data[0].blockNumber).toBe("string"); + expect(typeof data[0].blockTimestamp).toBe("string"); + }); + + const pageParams = [ + { pagination: { offset: 0, limit: 5 } }, + { pagination: { offset: 1, limit: 4 } }, + { pagination: { offset: 2, limit: 3 } }, + ]; + for (const { pagination } of pageParams) { + test(`Should return Royalty Policies list with pagination ${JSON.stringify( + pagination + )}`, async ({ request }) => { + const payload = { + options: { pagination: pagination }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const offsetResponse = await request.post(endpoint, { + data: { options: { pagination: { limit: 30 } } }, + }); + const offsetJson = await offsetResponse.json(); + const firstItem = offsetJson.data[pagination.offset]; + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + expect(data.length).toBeLessThanOrEqual(pagination.limit); + expect(data[0]).toMatchObject(firstItem); + }); + } + + const orderParams = [ + { orderBy: "id", orderDirection: "desc" }, + { orderBy: "id", orderDirection: "asc" }, + { orderBy: "royaltyStack", orderDirection: "desc" }, + { orderBy: "royaltyStack", orderDirection: "asc" }, + { orderBy: "splitClone", orderDirection: "desc" }, + { orderBy: "splitClone", orderDirection: "asc" }, + { orderBy: "ancestorsVault", orderDirection: "desc" }, + { orderBy: "ancestorsVault", orderDirection: "asc" }, + { orderBy: "blockNumber", orderDirection: "desc" }, + { orderBy: "blockNumber", orderDirection: "asc" }, + { orderBy: "blockTimestamp", orderDirection: "desc" }, + { orderBy: "blockTimestamp", orderDirection: "asc" }, + ]; + for (const { orderBy, orderDirection } of orderParams) { + test(`Should return Royalty Policies list ordered by ${orderBy} ${orderDirection}`, async ({ + request, + }) => { + const payload = { + options: { orderBy, orderDirection }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + expect(data.length).toBeGreaterThan(0); + for (let i = 0; i < data.length - 1; i++) { + let item: string | number; + let nextItem: string | number; + if (orderBy === "royaltyStack") { + item = parseInt(data[i][orderBy]); + nextItem = parseInt(data[i + 1][orderBy]); + } else { + item = data[i][orderBy].trim() || "\uFFFF"; + nextItem = data[i + 1][orderBy].trim() || "\uFFFF"; + } + if (orderDirection === "asc") { + expect(item <= nextItem).toBeTruthy(); + } else { + expect(item >= nextItem).toBeTruthy(); + } + } + }); + } + + const pageAndOrderParams = [ + { + pagination: { offset: 0, limit: 5 }, + orderBy: "id", + orderDirection: "asc", + }, + { + pagination: { offset: 1, limit: 3 }, + orderBy: "ancestorsVault", + orderDirection: "desc", + }, + ]; + for (const { pagination, orderBy, orderDirection } of pageAndOrderParams) { + test(`Should return Royalty Policies list with pagination ${JSON.stringify( + pagination + )} ordered by ${orderBy} ${orderDirection}`, async ({ request }) => { + const payload = { + options: { pagination, orderBy, orderDirection }, + }; + const response = await request.post(endpoint, { + data: payload, + }); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + expect(data.length).toBeGreaterThan(0); + expect(data.length).toBeLessThanOrEqual(pagination.limit); + for (let i = 0; i < data.length - 1; i++) { + const item = data[i][orderBy].trim() || "\uFFFF"; + const nextItem = data[i + 1][orderBy].trim() || "\uFFFF"; + if (orderDirection === "asc") { + expect(item <= nextItem).toBeTruthy(); + } else { + expect(item >= nextItem).toBeTruthy(); + } + } + }); + } +}); diff --git a/tests/api/royalties/royalties.splits.get.spec.ts b/tests/api/royalties/royalties.splits.get.spec.ts new file mode 100644 index 0000000..579efda --- /dev/null +++ b/tests/api/royalties/royalties.splits.get.spec.ts @@ -0,0 +1,40 @@ +import { test, expect } from "../fixtures/base"; +import { ApiPrefix } from "../../constants"; + +const endpoint = ApiPrefix + "/royalties/splits"; + +test.describe("Get a Royalties Split @Royalties", () => { + test("Should return Royalties Split detail", async ({ + request, + royaltiesPolicies, + }) => { + const params = [ + { royaltySplitId: royaltiesPolicies[1].splitClone, exists: true }, + { + royaltySplitId: "0x53da49b421effb384e66a64f4fba28925c569999", + exists: false, + }, + ]; + for (const { royaltySplitId, exists } of params) { + await test.step(`Query with royaltySplitId ${royaltySplitId}`, async () => { + const response = await request.get(endpoint + `/${royaltySplitId}`); + expect(response.status()).toBe(200); + + const { errors, data } = await response.json(); + expect(errors).toBeUndefined(); + if (exists) { + expect(data.id).toBe(royaltySplitId); + expect(typeof data.claimFromIPPoolArg).toBe("string"); + expect(Array.isArray(data.holders)).toBeTruthy(); + } else { + expect(data).toBeNull(); + } + }); + } + }); + + test("Should return 404 for no royaltySplitId", async ({ request }) => { + const response = await request.get(endpoint); + expect(response.status()).toBe(404); + }); +}); diff --git a/tests/api/transactions/transactions.post.spec.ts b/tests/api/transactions/transactions.post.spec.ts index 0173670..0796f41 100644 --- a/tests/api/transactions/transactions.post.spec.ts +++ b/tests/api/transactions/transactions.post.spec.ts @@ -138,8 +138,16 @@ test.describe("List Transactions @Transactions", async () => { request, transactions, }) => { + const filterEmptyData = transactions.filter((t) => t.ipId); const whereParams = [ - { where: { ipId: transactions[1].ipId }, exists: true }, + { + where: { + ipId: filterEmptyData + ? filterEmptyData[0].ipId + : transactions[0].ipId, + }, + exists: true, + }, { where: { ipId: "0x6465a15fc665329d7b129987f1fc4f824c579999" }, exists: false, @@ -152,8 +160,12 @@ test.describe("List Transactions @Transactions", async () => { { where: { actionType: transactions[1].actionType }, exists: true }, { where: { - ipId: transactions[1].ipId, - actionType: transactions[1].actionType, + ipId: filterEmptyData + ? filterEmptyData[0].ipId + : transactions[0].ipId, + actionType: filterEmptyData + ? filterEmptyData[0].actionType + : transactions[0].actionType, }, exists: true, }, @@ -179,8 +191,10 @@ test.describe("List Transactions @Transactions", async () => { expect(errors).toBeUndefined(); if (exists) { expect(data.length).toBeGreaterThan(0); - for (const item of data) { - expect(item).toMatchObject(where); + if (where.ipId?.trim() !== "") { + for (const item of data) { + expect(item).toMatchObject(where); + } } } else { expect(data.length).toBe(0); @@ -195,14 +209,14 @@ test.describe("List Transactions @Transactions", async () => { }) => { const params = [ { - where: { ipId: transactions[1].ipId }, + where: { actionType: transactions[1].actionType }, orderBy: "id", orderDirection: "asc", pagination: { offset: 1, limit: 5 }, }, { where: { - ipId: transactions[1].ipId, + actionType: transactions[1].actionType, resourceId: transactions[0].resourceId, }, orderBy: "ipId",