Skip to content

Instantly share code, notes, and snippets.

@rts-rob
Created November 29, 2021 18:22
Show Gist options
  • Save rts-rob/d224582af0b73efa76011df599c1078f to your computer and use it in GitHub Desktop.
Save rts-rob/d224582af0b73efa76011df599c1078f to your computer and use it in GitHub Desktop.
Composing unit tests in FQL
// Copyright Fauna, Inc.
// SPDX-License-Identifier: MIT-0
import { IsWidget } from '../src/widget/lib';
// Test setup, etc.
test('Widgets are identified correctly', async () => {
const result = await faunaClient.query(
Let({
widget: widgetName
},
IsWidget(Var("widget"))
));
expect(result).toBeTruthy();
});
// Copyright Fauna, Inc.
// SPDX-License-Identifier: MIT-0
export function IsWidget(name: faunadb.Expr): faunadb.Expr {
return Let(
{
collection: Collection(name),
metadata: Select(["data"], Get(Var("collection")), { widget: false }),
isWidget: Select(["widget"], Var("metadata"))
},
Equals(Var("isWidget"), true)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment