Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test --include options #536

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/query.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from "../lib/errors.mjs";
import {
formatError,
formatQueryInfo,
formatQueryResponse,
getSecret,
} from "../lib/fauna-client.mjs";
Expand Down Expand Up @@ -71,6 +70,7 @@ const resolveInput = (argv) => {
};

async function queryCommand(argv) {
const formatQueryInfo = container.resolve("formatQueryInfo");
const logger = container.resolve("logger");

// Run validation here instead of via check for more control over output
Expand Down
9 changes: 3 additions & 6 deletions src/commands/shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
validateDatabaseOrSecret,
yargsWithCommonConfigurableQueryOptions,
} from "../lib/command-helpers.mjs";
import {
formatQueryInfo,
formatQueryResponse,
getSecret,
} from "../lib/fauna-client.mjs";
import { formatQueryResponse, getSecret } from "../lib/fauna-client.mjs";
import { clearHistoryStorage, initHistoryStorage } from "../lib/file-util.mjs";

async function shellCommand(argv) {
Expand All @@ -39,7 +35,7 @@
prompt: `${argv.database || ""}> `,
ignoreUndefined: true,
preview: argv.apiVersion !== "10",
// TODO: integrate with fql-analyzer for completions

Check warning on line 38 in src/commands/shell.mjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: integrate with fql-analyzer for...'
completer: argv.apiVersion === "10" ? () => [] : undefined,
output: container.resolve("stdoutStream"),
input: container.resolve("stdinStream"),
Expand Down Expand Up @@ -150,8 +146,9 @@

// caches the logger, client, and performQuery for subsequent shell calls
async function buildCustomEval(argv) {
const runQueryFromString = container.resolve("runQueryFromString");
const formatError = container.resolve("formatError");
const formatQueryInfo = container.resolve("formatQueryInfo");
const runQueryFromString = container.resolve("runQueryFromString");

return async (cmd, ctx, _filename, cb) => {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/config/setup-container.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { makeRetryableFaunaRequest } from "../lib/db.mjs";
import * as faunaV10 from "../lib/fauna.mjs";
import {
formatError,
formatQueryInfo,
isQueryable,
runQueryFromString,
} from "../lib/fauna-client.mjs";
Expand Down Expand Up @@ -98,6 +99,7 @@ export const injectables = {
// utilities for interacting with Fauna
runQueryFromString: awilix.asValue(runQueryFromString),
formatError: awilix.asValue(formatError),
formatQueryInfo: awilix.asValue(formatQueryInfo),
faunaClientV10: awilix.asValue(faunaV10),
faunaClientV4: awilix.asValue(faunaV4),
isQueryable: awilix.asValue(isQueryable),
Expand Down
2 changes: 2 additions & 0 deletions src/config/setup-test-container.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { f, InMemoryWritableStream } from "../../test/helpers.mjs";
import { parseYargs } from "../cli.mjs";
import { makeRetryableFaunaRequest } from "../lib/db.mjs";
import * as faunaClientV10 from "../lib/fauna.mjs";
import { formatQueryInfo } from "../lib/fauna-client.mjs";
import * as faunaClientV4 from "../lib/faunadb.mjs";
import buildLogger from "../lib/logger.mjs";
import { injectables, setupCommonContainer } from "./setup-container.mjs";
Expand Down Expand Up @@ -106,6 +107,7 @@ export function setupTestContainer() {
runQueryFromString: awilix.asValue(stub().resolves({})),
isQueryable: awilix.asValue(stub().resolves()),
formatError: awilix.asValue(stub()),
formatQueryInfo: awilix.asValue(spy(formatQueryInfo)),
faunaClientV10: awilix.asValue({
getClient: stub(),
runQuery: stub(),
Expand Down
42 changes: 39 additions & 3 deletions test/query.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sinon from "sinon";

import { run } from "../src/cli.mjs";
import { setupTestContainer as setupContainer } from "../src/config/setup-test-container.mjs";
import { QUERY_INFO_CHOICES } from "../src/lib/command-helpers.mjs";
import { NETWORK_ERROR_MESSAGE } from "../src/lib/errors.mjs";
import { colorize } from "../src/lib/formatting/colorize.mjs";
import {
Expand Down Expand Up @@ -321,9 +322,44 @@ describe("query", function () {
});

// Add FormatQueryInfo to container in order to test which options are were passed
it.skip("can set the include option to an array");
it.skip("can specify '--include all' to set all include options");
it.skip("can specify '--include none' to set no include options");
it("can set the include option to '[summary]' by default", async function () {
const formatQueryInfo = container.resolve("formatQueryInfo");

await run(`query "foo" --secret=foo`, container);

expect(formatQueryInfo.getCall(0).args[1].include).to.deep.equal([
"summary",
]);
});
ptpaterson marked this conversation as resolved.
Show resolved Hide resolved

it("can set the include option to an array", async function () {
const formatQueryInfo = container.resolve("formatQueryInfo");

await run(`query "foo" --secret=foo --include summary stats`, container);

expect(formatQueryInfo.getCall(0).args[1].include).to.deep.equal([
"summary",
"stats",
]);
});

it("can specify '--include all' to set all include options", async function () {
const formatQueryInfo = container.resolve("formatQueryInfo");

await run(`query "foo" --secret=foo --include all`, container);

expect(formatQueryInfo.getCall(0).args[1].include).to.deep.equal(
QUERY_INFO_CHOICES,
);
});

it("can specify '--include none' to set no include options", async function () {
const formatQueryInfo = container.resolve("formatQueryInfo");

await run(`query "foo" --secret=foo --include none`, container);

expect(formatQueryInfo).to.not.be.called;
});

it("displays summary by default", async function () {
runQueryFromString.resolves({
Expand Down
Loading