Skip to content

Commit

Permalink
dev: add explicit jsonquery test with client
Browse files Browse the repository at this point in the history
  • Loading branch information
tefkah committed Feb 26, 2025
1 parent 0935bb5 commit 55b9d24
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions core/playwright/site-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ let client: ReturnType<typeof initClient<typeof siteApi, any>>;

let token: string;

const createClient = (token: string, jsonQuery: boolean = false) => {
return initClient(siteApi, {
baseUrl: `http://localhost:3000/`,
baseHeaders: {
Authorization: `Bearer ${token}`,
},
jsonQuery,
});
};

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();

Expand All @@ -41,14 +51,7 @@ test.beforeAll(async ({ browser }) => {
expect(createdToken).not.toBeNull();
token = createdToken!;

client = initClient(siteApi, {
baseUrl: `http://localhost:3000/`,
baseHeaders: {
Authorization: `Bearer ${token}`,
},
// necessary else filters will not work
jsonQuery: true,
});
client = createClient(token, true);
});

test.describe("Site API", () => {
Expand Down Expand Up @@ -183,6 +186,26 @@ test.describe("Site API", () => {
expect(response.body[0].id).not.toBe(newPubId);
});

test("should be able to filter by without jsonQuery", async () => {
const client = createClient(token, false);
const response = await client.pubs.getMany({
params: {
communitySlug: COMMUNITY_SLUG,
},
query: {
filters: {
createdAt: {
$gte: firstCreatedAt,
},
},
},
});

expectStatus(response, 200);
expect(response.body).toHaveLength(1);
expect(response.body[0].id).not.toBe(newPubId);
});

test("should be able to filter by updatedAt", async () => {
const updatedAtDate = new Date();
const updatedPub = await client.pubs.update({
Expand Down

0 comments on commit 55b9d24

Please sign in to comment.