Skip to content

Commit

Permalink
feature(groq-builder): added tests for mixed projections
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrippey committed Nov 4, 2023
1 parent e71d800 commit 1baf125
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions packages/groq-builder/src/commands/projection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,68 @@ describe("projection (objects)", () => {
`);
});
});

describe("mixed projections", () => {
const qComplex = qVariants.projection((q) => ({
name: true,
slug: q.projection("slug").projection("current"),
price: true,
IMAGES: q.projection("images[]").projection("name"),
}));

it("query should be correct", () => {
expect(qComplex.query).toMatchInlineSnapshot(
'"*[_type == \\"variant\\"]{ name, \\"slug\\": slug.current, price, \\"IMAGES\\": images[].name }"'
);
});

it("types should be correct", () => {
expectType<ExtractScope<typeof qComplex>>().toStrictEqual<
Array<{
name: string;
slug: string;
price: number;
IMAGES: Array<string>;
}>
>();
});

it("should execute correctly", async () => {
const results = await executeBuilder(data.datalake, qComplex);
expect(results).toMatchInlineSnapshot(`
[
{
"IMAGES": [],
"name": "Variant 0",
"price": 0,
"slug": "variant:0",
},
{
"IMAGES": [],
"name": "Variant 1",
"price": 100,
"slug": "variant:1",
},
{
"IMAGES": [],
"name": "Variant 2",
"price": 200,
"slug": "variant:2",
},
{
"IMAGES": [],
"name": "Variant 3",
"price": 300,
"slug": "variant:3",
},
{
"IMAGES": [],
"name": "Variant 4",
"price": 400,
"slug": "variant:4",
},
]
`);
});
});
});

0 comments on commit 1baf125

Please sign in to comment.