Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyitang committed May 14, 2024
1 parent 3ac53b5 commit 0b7b5cf
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/api/collections/collections.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test.describe("List Collections @Collections", async () => {
const pageParams = [
{ pagination: { offset: 0, limit: 5 } },
{ pagination: { offset: 0, limit: 1 } },
{ pagination: { offset: 1, limit: 20 } },
{ pagination: { offset: 1, limit: 5 } },
];
for (const { pagination } of pageParams) {
test(`Should return Collections list with pagination ${JSON.stringify(
Expand All @@ -54,7 +54,7 @@ test.describe("List Collections @Collections", async () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 30 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand Down
2 changes: 2 additions & 0 deletions tests/api/fixtures/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ type TestOptions = {
}>;
licensesIpTerms: Array<{
id: string;
ipId: string;
}>;
licensesTokens: Array<{
id: string;
licensorIpId: string;
}>;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/api/ipassets/assets.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test.describe("List IPAssets @IPAssets", async () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 30 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand Down
35 changes: 33 additions & 2 deletions tests/api/licenses/licenses-ip-terms.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test.describe("List LicenseIpTerms @Licenses", () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 30 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand All @@ -58,5 +58,36 @@ test.describe("List LicenseIpTerms @Licenses", () => {
expect(data[0]).toMatchObject(firstItem);
});
}
});

test("query with filter", async ({ request, licensesIpTerms }) => {
const whereParams = [
{ where: { ipId: licensesIpTerms[1].ipId }, exists: true },
{
where: { ipId: "0xe7517E0Ee3e255a904BD777961C20566be089999" },
exists: false,
},
];
for (const { where, exists } of whereParams) {
await test.step(`query with where ${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);
data.forEach((item: object) => {
expect(item).toMatchObject(where);
});
} else {
expect(data.length).toBe(0);
}
});
}
});
});
2 changes: 1 addition & 1 deletion tests/api/licenses/licenses-templates.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.describe("List LicenseTemplates @Licenses", () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 30 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand Down
2 changes: 1 addition & 1 deletion tests/api/licenses/licenses-terms.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.describe("List LicenseTerms @Licenses", () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 30 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand Down
32 changes: 31 additions & 1 deletion tests/api/licenses/licenses-tokens.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,34 @@ test.describe("List LicenseTokens @Licenses", () => {
expect(data[0]).toMatchObject(firstItem);
});
}
});

test("query with filter", async ({ request, licensesTokens }) => {
const whereParams = [
{ where: { licensorIpId: licensesTokens[1].licensorIpId }, exists: true },
{
where: { licensorIpId: "0x5FCeDadBbDF710Ac3C528F6Aac9D1bD9ac189999" },
exists: false,
},
];
for (const { where, exists } of whereParams) {
await test.step(`query with where ${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);
expect(data[0].licensorIpId).toBe(licensesTokens[1].licensorIpId);
} else {
expect(data.length).toBe(0);
}
});
}
});
});
2 changes: 1 addition & 1 deletion tests/api/permissions/permissions.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test.describe("List Permissions @Permissions", async () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 30 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand Down
2 changes: 1 addition & 1 deletion tests/api/royalties/royalties-payments.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test.describe("List RoyaltyPays @Royalties", () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 30 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand Down

0 comments on commit 0b7b5cf

Please sign in to comment.