Skip to content

Commit

Permalink
Merge pull request #20 from storyprotocol/update-config
Browse files Browse the repository at this point in the history
Update tests for the latest API version
  • Loading branch information
AndyBoWu authored Apr 15, 2024
2 parents ebc9db8 + 3bc5772 commit bf52dc6
Show file tree
Hide file tree
Showing 36 changed files with 144 additions and 166 deletions.
24 changes: 11 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,23 @@ jobs:
run: pnpm eslint .
# Ensure you have a lint script in your package.json

- name: Run Tests On Seplia
- name: Run Tests On Sepolia
continue-on-error: true
run: |
echo "Load environment variables"
rm .env.sepolia && touch .env.sepolia
echo API_BASE_URL=${{ secrets.API_BASE_URL }} > .env.sepolia
echo API_PREFIX=${{ secrets.API_PREFIX_SEPOLIA }} >> .env.sepolia
echo API_KEY=${{ secrets.API_KEY }} >> .env.sepolia
rm .env && touch .env
echo API_BASE_URL=${{ secrets.API_BASE_URL }} > .env
echo API_KEY=${{ secrets.API_KEY }} >> .env
test_env=sepolia npx playwright test
- name: Run Tests On Renaissance
- name: Run Tests On Story
continue-on-error: true
run: |
echo "Load environment variables"
rm .env.renaissance && touch .env.renaissance
echo API_BASE_URL=${{ secrets.API_BASE_URL }} > .env.renaissance
echo API_PREFIX=${{ secrets.API_PREFIX_RENAISSANCE }} >> .env.renaissance
echo API_KEY=${{ secrets.API_KEY }} >> .env.renaissance
test_env=renaissance npx playwright test
rm .env && touch .env
echo API_BASE_URL=${{ secrets.API_BASE_URL }} > .env
echo API_KEY=${{ secrets.API_KEY }} >> .env
test_env=story npx playwright test
- name: Push Slack Notification
uses: slackapi/[email protected]
Expand Down Expand Up @@ -106,6 +104,6 @@ jobs:
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
# if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
name: renaissance-test-reports
name: story-test-reports
path: |
./playwright-report-renaissance/index.html
./playwright-report-story/index.html
3 changes: 1 addition & 2 deletions ci.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
API_BASE_URL="https://edge.stg.storyprotocol.net"
API_BASE_URL = "https://edge.stg.storyprotocol.net/api/v1/"
API_KEY=#API_KEY#
API_PREFIX="/api/sepolia/v1"
8 changes: 0 additions & 8 deletions global-setup.ts

This file was deleted.

4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import { defineConfig } from '@playwright/test';
import dotenv from 'dotenv';
dotenv.config();

const EnvName = process.env.test_env || '';
const EnvName = process.env.test_env || 'story';

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
globalSetup: require.resolve('./global-setup'),
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
Expand Down Expand Up @@ -49,6 +48,7 @@ export default defineConfig({
// Add authorization token to all requests.
// Assuming personal access token available in the environment.
'X-API-Key': process.env.API_KEY || '',
'X-CHAIN': `${EnvName}`,
},
}
},
Expand Down
3 changes: 1 addition & 2 deletions tests/api/collections/collections.get.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test, expect } from "../fixtures/base";
import { ApiPrefix } from "../../constants";

const endpoint = ApiPrefix + "/collections";
const endpoint = "./collections";

test.describe("Get a Collection @Collections", async () => {
test("Should return a Collection detail", async ({
Expand Down
3 changes: 1 addition & 2 deletions tests/api/collections/collections.post.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test, expect } from "@playwright/test";
import { ApiPrefix } from "../../constants";

const endpoint = ApiPrefix + "/collections";
const endpoint = "./collections";

test.describe("List Collections @Collections", async () => {
test("Should return default Collections list", async ({ request }) => {
Expand Down
3 changes: 1 addition & 2 deletions tests/api/disputes/disputes.get.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test, expect } from "../fixtures/base";
import { ApiPrefix } from "../../constants";

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

test.describe("Get a Dispute @Disputes", async () => {
test("Should return the Dispute detail", async ({ request, disputes }) => {
Expand Down
35 changes: 20 additions & 15 deletions tests/api/disputes/disputes.post.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test, expect } from "../fixtures/base";
import { ApiPrefix } from "../../constants";

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

test.describe("List Disputes @Disputes", async () => {
test("Should return default Disputes list", async ({ request }) => {
Expand Down Expand Up @@ -32,7 +31,7 @@ test.describe("List Disputes @Disputes", async () => {
for (const { pagination } of pageParams) {
test(`Should return Disputes list with pagination ${JSON.stringify(
pagination
)}`, async ({ request }) => {
)}`, async ({ request, disputes }) => {
const payload = {
options: { pagination: pagination },
};
Expand All @@ -49,8 +48,10 @@ test.describe("List Disputes @Disputes", async () => {

const { errors, data } = await response.json();
expect(errors).toBeUndefined();
expect(data.length).toBe(pagination.limit);
expect(data[0]).toMatchObject(firstItem);
expect(data.length).toBeLessThanOrEqual(pagination.limit);
if (pagination.offset < disputes.length) {
expect(data[0]).toMatchObject(firstItem);
}
});
}

Expand Down Expand Up @@ -118,7 +119,7 @@ test.describe("List Disputes @Disputes", async () => {
for (const { pagination, orderBy, orderDirection } of pageAndOrderParams) {
test(`Should return Disputes list with pagination ${JSON.stringify(
pagination
)} ordered by ${orderBy} ${orderDirection}`, async ({ request }) => {
)} ordered by ${orderBy} ${orderDirection}`, async ({ request, disputes }) => {
const payload = {
options: { pagination, orderBy, orderDirection },
};
Expand All @@ -129,8 +130,10 @@ test.describe("List Disputes @Disputes", async () => {

const { errors, data } = await response.json();
expect(errors).toBeUndefined();
expect(data.length).toBeGreaterThan(0);
expect(data.length).toBe(pagination.limit);
if (pagination.offset < disputes.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";
Expand All @@ -151,7 +154,7 @@ test.describe("List Disputes @Disputes", async () => {
const whereParams = [
{
where: {
targetTag: disputes[1].targetTag,
targetTag: disputes[0].targetTag,
},
exists: true,
},
Expand Down Expand Up @@ -186,7 +189,7 @@ test.describe("List Disputes @Disputes", async () => {
exists: false,
},
{
where: { initiator: disputes[1].initiator },
where: { initiator: disputes[0].initiator },
exists: true,
},
{
Expand All @@ -195,8 +198,8 @@ test.describe("List Disputes @Disputes", async () => {
},
{
where: {
targetTag: disputes[1].targetTag,
targetIpId: disputes[1].targetIpId,
targetTag: disputes[0].targetTag,
targetIpId: disputes[0].targetIpId,
},
exists: true,
},
Expand Down Expand Up @@ -247,8 +250,8 @@ test.describe("List Disputes @Disputes", async () => {
orderBy: "id",
orderDirection: "desc",
where: {
targetTag: disputes[1].targetTag,
initiator: disputes[1].initiator,
targetTag: disputes[0].targetTag,
initiator: disputes[0].initiator,
},
},
{
Expand Down Expand Up @@ -277,7 +280,9 @@ test.describe("List Disputes @Disputes", async () => {

const { errors, data } = await response.json();
expect(errors).toBeUndefined();
expect(data.length).toBeGreaterThan(0);
if (p.pagination.offset < disputes.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";
Expand Down
34 changes: 18 additions & 16 deletions tests/api/fixtures/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test as base } from "@playwright/test";
import { ApiPrefix } from "../../constants";

type TestOptions = {
assets: Array<{
Expand All @@ -8,6 +7,9 @@ type TestOptions = {
tokenId: string;
metadataResolverAddress: string;
tokenContract: string;
metadata: {
registrant: string;
}
}>;
disputes: Array<{
id: string;
Expand All @@ -28,7 +30,7 @@ type TestOptions = {
}>;
licenses: Array<{
id: string;
policyId: string;
licenseTermsId: string;
licensorIpId: string;
transferable: boolean;
}>;
Expand Down Expand Up @@ -84,72 +86,72 @@ type TestOptions = {

export const test = base.extend<TestOptions>({
assets: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/assets");
const response = await request.post("./assets");
const { data } = await response.json();
await use(data);
},
disputes: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/disputes");
const response = await request.post("./disputes");
const { data } = await response.json();
await use(data);
},
collections: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/collections");
const response = await request.post("./collections");
const { data } = await response.json();
await use(data);
},
ipapolicies: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/ipapolicies");
const response = await request.post("./ipapolicies");
const { data } = await response.json();
await use(data);
},
licenses: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/licenses");
const response = await request.post("./licenses");
const { data } = await response.json();
await use(data);
},
licensesMintingfees: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/licenses/mintingfees");
const response = await request.post("./licenses/mintingfees");
const { data } = await response.json();
await use(data);
},
licensesOwners: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/licenses/owners");
const response = await request.post("./licenses/owners");
const { data } = await response.json();
await use(data);
},
modules: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/modules");
const response = await request.post("./modules");
const { data } = await response.json();
await use(data);
},
permissionsList: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/permissions");
const response = await request.post("./permissions");
const { data } = await response.json();
await use(data);
},
policies: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/policies");
const response = await request.post("./policies");
const { data } = await response.json();
await use(data);
},
policiesFrameworks: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/policies/frameworks");
const response = await request.post("./policies/frameworks");
const { data } = await response.json();
await use(data);
},
transactions: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/transactions");
const response = await request.post("./transactions");
const { data } = await response.json();
await use(data);
},
royaltiesPayments: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/royalties/payments");
const response = await request.post("./royalties/payments");
const { data } = await response.json();
await use(data);
},
royaltiesPolicies: async ({ request }, use) => {
const response = await request.post(ApiPrefix + "/royalties/policies");
const response = await request.post("./royalties/policies");
const { data } = await response.json();
await use(data);
},
Expand Down
Loading

0 comments on commit bf52dc6

Please sign in to comment.