Skip to content

Commit

Permalink
Merge pull request #25 from storyprotocol/fix-tests-1
Browse files Browse the repository at this point in the history
update tests
  • Loading branch information
AndyBoWu authored May 7, 2024
2 parents 37b807b + 2561dc5 commit d3f01a6
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 317 deletions.
67 changes: 30 additions & 37 deletions tests/api/collections/collections.get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,37 @@ test.describe("Get a Collection @Collections", async () => {
request,
collections,
}) => {
const params = [
{ collectionId: collections[0].id, exists: true },
{
collectionId: "0x6456cba1cf7189a5e51a207fe232574e1fc21999",
exists: false,
},
];
for (const { collectionId, exists } of params) {
await test.step(`Should return the Collection detail with collectionId ${collectionId}`, async () => {
const response = await request.get(endpoint + `/${collectionId}`);
expect(response.status()).toBe(200);
const collectionId = collections[0].id;
const response = await request.get(endpoint + `/${collectionId}`);
expect(response.status()).toBe(200);

const { errors, data } = await response.json();
expect(errors).toBeUndefined();
if (exists) {
expect(data.id).toBe(collectionId);
expect(typeof data.assetCount).toBe("string");
expect(typeof data.licensesCount).toBe("string");
expect(typeof data.raisedDisputeCount).toBe("string");
expect(typeof data.judgedDisputeCount).toBe("string");
expect(typeof data.resolvedDisputeCount).toBe("string");
expect(typeof data.cancelledDisputeCount).toBe("string");
expect(typeof data.blockNumber).toBe("string");
expect(typeof data.blockTimestamp).toBe("string");
expect(data.id).toBeTruthy();
expect(data.assetCount).toBeTruthy();
expect(data.licensesCount).toBeTruthy();
expect(data.raisedDisputeCount).toBeTruthy();
expect(data.judgedDisputeCount).toBeTruthy();
expect(data.resolvedDisputeCount).toBeTruthy();
expect(data.cancelledDisputeCount).toBeTruthy();
expect(data.blockNumber).toBeTruthy();
expect(data.blockTimestamp).toBeTruthy();
} else {
expect(data.id).toBeFalsy();
}
});
}
const { errors, data } = await response.json();
expect(errors).toBeUndefined();
expect(data.id).toBe(collectionId);
expect.soft(typeof data.assetCount).toBe("string");
expect.soft(typeof data.licensesCount).toBe("string");
expect.soft(typeof data.raisedDisputeCount).toBe("string");
expect.soft(typeof data.judgedDisputeCount).toBe("string");
expect.soft(typeof data.resolvedDisputeCount).toBe("string");
expect.soft(typeof data.cancelledDisputeCount).toBe("string");
expect.soft(typeof data.blockNumber).toBe("string");
expect.soft(typeof data.blockTimestamp).toBe("string");
expect.soft(data.id).toBeTruthy();
expect.soft(data.assetCount).toBeTruthy();
expect.soft(data.licensesCount).toBeTruthy();
expect.soft(data.raisedDisputeCount).toBeTruthy();
expect.soft(data.judgedDisputeCount).toBeTruthy();
expect.soft(data.resolvedDisputeCount).toBeTruthy();
expect.soft(data.cancelledDisputeCount).toBeTruthy();
expect.soft(data.blockNumber).toBeTruthy();
expect.soft(data.blockTimestamp).toBeTruthy();
});

test("Should return 404 for non-exist collectionId", async ({ request }) => {
const response = await request.get(
endpoint + "/0x6456cba1cf7189a5e51a207fe232574e1fc21999"
);
expect(response.status()).toBe(404);
});

test("Should return 404 for no collectionId", async ({ request }) => {
Expand Down
64 changes: 29 additions & 35 deletions tests/api/disputes/disputes.get.spec.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
import { test, expect } from "../fixtures/base";

const endpoint = "./disputes";
const endpoint = "./disputes";

test.describe("Get a Dispute @Disputes", async () => {
test("Should return the Dispute detail", async ({ request, disputes }) => {
const params = [
{ disputeId: disputes[1].id, exists: true },
{ disputeId: "0", exists: false },
];
for (const { disputeId, exists } of params) {
await test.step(`Should return the Dispute detail with disputeId ${disputeId}`, async () => {
const response = await request.get(endpoint + `/${disputeId}`);
expect(response.status()).toBe(200);
const disputeId = disputes[1].id;
const response = await request.get(endpoint + `/${disputeId}`);
expect(response.status()).toBe(200);

const { errors, data } = await response.json();
expect(errors).toBeUndefined();
if (exists) {
expect(data.id).toBe(disputeId);
expect(typeof data.targetIpId).toBe("string");
expect(typeof data.targetTag).toBe("string");
expect(typeof data.currentTag).toBe("string");
expect(typeof data.arbitrationPolicy).toBe("string");
expect(typeof data.evidenceLink).toBe("string");
expect(typeof data.initiator).toBe("string");
expect(typeof data.data).toBe("string");
expect(typeof data.blockNumber).toBe("string");
expect(typeof data.blockTimestamp).toBe("string");
expect(data.id).toBeTruthy();
expect(data.targetIpId).toBeTruthy();
expect(data.targetTag).toBeTruthy();
expect(data.arbitrationPolicy).toBeTruthy();
expect(data.evidenceLink).toBeTruthy();
expect(data.initiator).toBeTruthy();
expect(data.blockNumber).toBeTruthy();
expect(data.blockTimestamp).toBeTruthy();
} else {
expect(data.id).toBeFalsy();
}
});
}
const { errors, data } = await response.json();
expect(errors).toBeUndefined();
expect(data.id).toBe(disputeId);
expect.soft(typeof data.targetIpId).toBe("string");
expect.soft(typeof data.targetTag).toBe("string");
expect.soft(typeof data.currentTag).toBe("string");
expect.soft(typeof data.arbitrationPolicy).toBe("string");
expect.soft(typeof data.evidenceLink).toBe("string");
expect.soft(typeof data.initiator).toBe("string");
expect.soft(typeof data.data).toBe("string");
expect.soft(typeof data.blockNumber).toBe("string");
expect.soft(typeof data.blockTimestamp).toBe("string");
expect.soft(data.id).toBeTruthy();
expect.soft(data.targetIpId).toBeTruthy();
expect.soft(data.targetTag).toBeTruthy();
expect.soft(data.arbitrationPolicy).toBeTruthy();
expect.soft(data.evidenceLink).toBeTruthy();
expect.soft(data.initiator).toBeTruthy();
expect.soft(data.blockNumber).toBeTruthy();
expect.soft(data.blockTimestamp).toBeTruthy();
});

test("Should return 404 for non-exist disputeId", async ({ request }) => {
const response = await request.get(endpoint + "/0");
expect(response.status()).toBe(404);
});

test("Should return 404 for no disputeId", async ({ request }) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api/disputes/disputes.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test.describe("List Disputes @Disputes", async () => {
expect(response.status()).toBe(200);

const offsetResponse = await request.post(endpoint, {
data: { options: { pagination: { limit: 20 } } },
data: { options: { pagination: { limit: 5 } } },
});
const offsetJson = await offsetResponse.json();
const firstItem = offsetJson.data[pagination.offset];
Expand Down Expand Up @@ -266,7 +266,7 @@ test.describe("List Disputes @Disputes", async () => {
},
},
{
pagination: { offset: 1, limit: 3 },
pagination: { offset: 0, limit: 3 },
orderBy: "targetIpId",
orderDirection: "asc",
where: {
Expand Down
69 changes: 32 additions & 37 deletions tests/api/ipassets/assets.get.spec.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
import { test, expect } from "../fixtures/base";

const endpoint = "./assets";
const endpoint = "./assets";

test.describe("Get an IPAsset @IPAssets", () => {
test("Should return the IPAsset detail", async ({ request, assets }) => {
const params = [
{ assetId: assets[1].id, exists: true },
{ assetId: "0xac05ed0d029e2441067df38da387ea5b5e6d6999", exists: false },
];
for (const { assetId, exists } of params) {
await test.step(`Should return the IPAsset detail with assetId ${assetId}`, async () => {
const response = await request.get(endpoint + `/${assetId}`);
expect(response.status()).toBe(200);
const assetId = assets[1].id;
const response = await request.get(endpoint + `/${assetId}`);
expect(response.status()).toBe(200);

const { errors, data } = await response.json();
expect(errors).toBeUndefined();
if (exists) {
expect(data.id).toBe(assetId);
expect(Array.isArray(data.parentIpIds ?? [])).toBeTruthy();
expect(Array.isArray(data.childIpIds ?? [])).toBeTruthy();
expect(Array.isArray(data.rootIpIds ?? [])).toBeTruthy();
expect(typeof data.nftMetadata.name).toBe("string");
expect(typeof data.nftMetadata.chainId).toBe("string");
expect(typeof data.nftMetadata.tokenId).toBe("string");
expect(typeof data.nftMetadata.tokenUri).toBe("string");
expect(typeof data.nftMetadata.imageUrl).toBe("string");
expect(typeof data.nftMetadata.tokenContract).toBe("string");
expect(typeof data.blockNumber).toBe("string");
expect(typeof data.blockTimestamp).toBe("string");
expect(data.id).toBeTruthy();
expect(data.nftMetadata.name).toBeTruthy();
expect(data.nftMetadata.chainId).toBeTruthy();
expect(data.nftMetadata.tokenId).toBeTruthy();
expect(data.nftMetadata.tokenUri).toBeTruthy();
expect(data.nftMetadata.tokenContract).toBeTruthy();
expect(data.blockNumber).toBeTruthy();
expect(data.blockTimestamp).toBeTruthy();
} else {
expect(data.id).toBeFalsy();
}
});
}
const { errors, data } = await response.json();
expect(errors).toBeUndefined();
expect(data.id).toBe(assetId);
expect.soft(Array.isArray(data.parentIpIds ?? [])).toBeTruthy();
expect.soft(Array.isArray(data.childIpIds ?? [])).toBeTruthy();
expect.soft(Array.isArray(data.rootIpIds ?? [])).toBeTruthy();
expect.soft(typeof data.nftMetadata.name).toBe("string");
expect.soft(typeof data.nftMetadata.chainId).toBe("string");
expect.soft(typeof data.nftMetadata.tokenId).toBe("string");
expect.soft(typeof data.nftMetadata.tokenUri).toBe("string");
expect.soft(typeof data.nftMetadata.imageUrl).toBe("string");
expect.soft(typeof data.nftMetadata.tokenContract).toBe("string");
expect.soft(typeof data.blockNumber).toBe("string");
expect.soft(typeof data.blockTimestamp).toBe("string");
expect.soft(data.id).toBeTruthy();
expect.soft(data.nftMetadata.name).toBeTruthy();
expect.soft(data.nftMetadata.chainId).toBeTruthy();
expect.soft(data.nftMetadata.tokenId).toBeTruthy();
expect.soft(data.nftMetadata.tokenContract).toBeTruthy();
expect.soft(data.blockNumber).toBeTruthy();
expect.soft(data.blockTimestamp).toBeTruthy();
});

test("Should return 404 for non-exist assetId", async ({ request }) => {
const response = await request.get(
endpoint + "/0xac05ed0d029e2441067df38da387ea5b5e6d9999"
);
expect(response.status()).toBe(404);
});

test("Should return 404 for no assetId", async ({ request }) => {
Expand Down
3 changes: 1 addition & 2 deletions tests/api/ipassets/assets.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ test.describe("List IPAssets @IPAssets", async () => {
expect(data[0].nftMetadata.name).toBeTruthy();
expect(data[0].nftMetadata.chainId).toBeTruthy();
expect(data[0].nftMetadata.tokenId).toBeTruthy();
expect(data[0].nftMetadata.tokenUri).toBeTruthy();
expect(data[0].nftMetadata.tokenContract).toBeTruthy();
expect(data[0].blockNumber).toBeTruthy();
expect(data[0].blockTimestamp).toBeTruthy();
Expand Down Expand Up @@ -187,7 +186,7 @@ test.describe("List IPAssets @IPAssets", async () => {
},
},
{
pagination: { offset: 2, limit: 15 },
pagination: { offset: 0, limit: 3 },
orderBy: "id",
orderDirection: "desc",
where: {
Expand Down
31 changes: 15 additions & 16 deletions tests/api/licenses/licenses-ip-terms.get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ test.describe("Get LicenseIpTerm @Licenses", () => {
expect(errors).toBeUndefined();
if (exists) {
expect(data.id).toBe(licenseIpTermId);
expect(typeof data.ip_id).toBe("string");
expect(typeof data.license_template).toBe("string");
expect(typeof data.license_terms_id).toBe("string");
expect(typeof data.block_number).toBe("string");
expect(typeof data.block_time).toBe("string");
expect(data.id).toBeTruthy();
expect(data.ip_id).toBeTruthy();
expect(data.license_template).toBeTruthy();
expect(data.license_terms_id).toBeTruthy();
expect(data.block_number).toBeTruthy();
expect(data.block_time).toBeTruthy();
expect.soft(typeof data.ipId).toBe("string");
expect.soft(typeof data.licenseTemplate).toBe("string");
expect.soft(typeof data.licenseTermsId).toBe("string");
expect.soft(typeof data.blockNumber).toBe("string");
expect.soft(typeof data.blockTime).toBe("string");
expect.soft(data.ipId).toBeTruthy();
expect.soft(data.licenseTemplate).toBeTruthy();
expect.soft(data.licenseTermsId).toBeTruthy();
expect.soft(data.blockNumber).toBeTruthy();
expect.soft(data.blockTime).toBeTruthy();
} else {
expect(data).toMatchObject({
id: "",
ip_id: "",
license_template: "",
license_terms_id: "",
block_number: "",
block_time: "",
ipId: "",
licenseTemplate: "",
licenseTermsId: "",
blockNumber: "",
blockTime: "",
});
}
});
Expand Down
24 changes: 12 additions & 12 deletions tests/api/licenses/licenses-ip-terms.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ test.describe("List LicenseIpTerms @Licenses", () => {
expect(Array.isArray(data)).toBeTruthy();
expect(data.length).toBeGreaterThan(0);
expect(typeof data[0].id).toBe("string");
expect(typeof data[0].ip_id).toBe("string");
expect(typeof data[0].license_template).toBe("string");
expect(typeof data[0].license_terms_id).toBe("string");
expect(typeof data[0].block_number).toBe("string");
expect(typeof data[0].block_time).toBe("string");
expect(typeof data[0].ipId).toBe("string");
expect(typeof data[0].licenseTemplate).toBe("string");
expect(typeof data[0].licenseTermsId).toBe("string");
expect(typeof data[0].blockNumber).toBe("string");
expect(typeof data[0].blockTime).toBe("string");
expect(data[0].id).toBeTruthy();
expect(data[0].ip_id).toBeTruthy();
expect(data[0].license_template).toBeTruthy();
expect(data[0].license_terms_id).toBeTruthy();
expect(data[0].block_number).toBeTruthy();
expect(data[0].block_time).toBeTruthy();
expect(data[0].ipId).toBeTruthy();
expect(data[0].licenseTemplate).toBeTruthy();
expect(data[0].licenseTermsId).toBeTruthy();
expect(data[0].blockNumber).toBeTruthy();
expect(data[0].blockTime).toBeTruthy();
for (let i = 0; i < data.length - 1; i++) {
const item = parseInt(data[i].block_time);
const nextItem = parseInt(data[i + 1].block_time);
const item = parseInt(data[i].blockTime);
const nextItem = parseInt(data[i + 1].blockTime);
expect(item).toBeGreaterThanOrEqual(nextItem);
}
});
Expand Down
2 changes: 1 addition & 1 deletion tests/api/licenses/licenses-mintingfees.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test.describe("List Minting Fees @Licenses Minting Fees", 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[payload.options.pagination.offset];
Expand Down
24 changes: 12 additions & 12 deletions tests/api/licenses/licenses-templates.get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ test.describe("Get LicenseTemplate @Licenses", () => {
expect(errors).toBeUndefined();
if (exists) {
expect(data.id).toBe(licenseTemplateId);
expect(typeof data.name).toBe("string");
expect(typeof data.metadata_uri).toBe("string");
expect(typeof data.block_number).toBe("string");
expect(typeof data.block_time).toBe("string");
expect(data.id).toBeTruthy();
expect(data.name).toBeTruthy();
expect(data.metadata_uri).toBeTruthy();
expect(data.block_number).toBeTruthy();
expect(data.block_time).toBeTruthy();
expect.soft(typeof data.name).toBe("string");
expect.soft(typeof data.metadataUri).toBe("string");
expect.soft(typeof data.blockNumber).toBe("string");
expect.soft(typeof data.blockTime).toBe("string");
expect.soft(data.id).toBeTruthy();
expect.soft(data.name).toBeTruthy();
expect.soft(data.metadataUri).toBeTruthy();
expect.soft(data.blockNumber).toBeTruthy();
expect.soft(data.blockTime).toBeTruthy();
} else {
expect(data).toMatchObject({
id: "",
name: "",
metadata_uri: "",
block_number: "",
block_time: "",
metadataUri: "",
blockNumber: "",
blockTime: "",
});
}
});
Expand Down
Loading

0 comments on commit d3f01a6

Please sign in to comment.