Created
November 29, 2021 18:22
-
-
Save rts-rob/d224582af0b73efa76011df599c1078f to your computer and use it in GitHub Desktop.
Composing unit tests in FQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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