Skip to content

Commit

Permalink
Merge branch 'v3' into fe-6228-schema-pull-api
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson authored Dec 10, 2024
2 parents c7118cc + 4eed51c commit d0cf9d2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/commands/schema/schema.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ts-check

import { validateDatabaseOrSecret } from "../../lib/command-helpers.mjs";
import abandonCommand from "./abandon.mjs";
import commitCommand from "./commit.mjs";
import diffCommand from "./diff.mjs";
Expand All @@ -25,6 +26,7 @@ function buildSchema(yargs) {
.command(pushCommand)
.command(pullCommand)
.command(statusCommand)
.check(validateDatabaseOrSecret)
.demandCommand();
}

Expand Down
24 changes: 14 additions & 10 deletions src/commands/schema/status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "../../lib/command-helpers.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";
import { reformatFSL } from "../../lib/schema.mjs";
import { localSchemaOptions } from "./schema.mjs";

async function doStatus(argv) {
const logger = container.resolve("logger");
Expand All @@ -32,6 +33,7 @@ async function doStatus(argv) {
staged: "true",
version: statusResponse.version,
});

const validationResponse = await makeFaunaRequest({
argv,
path: "/schema/1/validate",
Expand Down Expand Up @@ -64,16 +66,18 @@ async function doStatus(argv) {
}

function buildStatusCommand(yargs) {
return yargsWithCommonQueryOptions(yargs).example([
[
"$0 schema status --database us/example",
"Get the staged schema status for the 'us/example' database.",
],
[
"$0 schema status --secret my-secret",
"Get the staged schema status for the database scoped to a secret.",
],
]);
return yargsWithCommonQueryOptions(yargs)
.options(localSchemaOptions)
.example([
[
"$0 schema status --database us/example",
"Get the staged schema status for the 'us/example' database.",
],
[
"$0 schema status --secret my-secret",
"Get the staged schema status for the database scoped to a secret.",
],
]);
}

export default {
Expand Down
35 changes: 35 additions & 0 deletions test/schema/schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//@ts-check

import { expect } from "chai";
import chalk from "chalk";

import { builtYargs, run } from "../../src/cli.mjs";
import { setupTestContainer as setupContainer } from "../../src/config/setup-test-container.mjs";

describe("schema", function () {
let container, logger;
beforeEach(() => {
container = setupContainer();
logger = container.resolve("logger");
});

[
{ command: "schema status" },
{ command: "schema push" },
{ command: "schema abandon" },
{ command: "schema diff" },
{ command: "schema pull" },
{ command: "schema commit" },
].forEach(({ command }) => {
it(`requires a database or secret to call: ${command}`, async function () {
try {
await run(command, container);
} catch (e) {}

expect(logger.stderr).to.have.been.calledWith(
`${chalk.reset(await builtYargs.getHelp())}\n\n${chalk.red("No database or secret specified. Please use either --database, --secret, or --local to connect to your desired Fauna database.")}`,
);
expect(container.resolve("parseYargs")).to.have.been.calledOnce;
});
});
});

0 comments on commit d0cf9d2

Please sign in to comment.