Skip to content

Commit

Permalink
Notify on schema push if no schema files are found (#507)
Browse files Browse the repository at this point in the history
* warn user if no fsl files are found

* remove .only

* throw a validation error

* fix import

---------

Co-authored-by: E. Cooper <[email protected]>
  • Loading branch information
henryfauna and ecooper authored Dec 11, 2024
1 parent fb4fdd2 commit 82fd6d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/commands/schema/push.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@ts-check

import path from "path";

import { container } from "../../cli.mjs";
import { ValidationError } from "../../lib/errors.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";
import { reformatFSL } from "../../lib/schema.mjs";
Expand All @@ -13,10 +16,16 @@ async function doPush(argv) {

const isStagedPush = !argv.active;
const secret = await getSecret();
const fslFiles = await gatherFSL(argv.dir);
const hasLocalSchema = fslFiles.length > 0;
const absoluteDirPath = path.resolve(argv.dir);
const fsl = reformatFSL(fslFiles);

const fsl = reformatFSL(await gatherFSL(argv.dir));

if (!argv.input) {
if (!hasLocalSchema) {
throw new ValidationError(
`No schema files (*.fsl) found in '${absoluteDirPath}'. Use '--dir' to specify a different directory, or create new .fsl files in this location.`,
);
} else if (!argv.input) {
const params = new URLSearchParams({
force: "true",
staged: argv.active ? "false" : "true",
Expand Down
19 changes: 18 additions & 1 deletion test/schema/push.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//@ts-check

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

import { run } from "../../src/cli.mjs";
import { builtYargs, run } from "../../src/cli.mjs";
import { setupTestContainer as setupContainer } from "../../src/config/setup-test-container.mjs";
import { reformatFSL } from "../../src/lib/schema.mjs";
import { buildUrl, f } from "../helpers.mjs";
Expand Down Expand Up @@ -31,6 +33,21 @@ describe("schema push", function () {
gatherFSL.resolves(fsl);
});

it("notifies the user when no schema files are found", async function () {
gatherFSL.resolves([]);
const absoluteDirPath = path.resolve(".");

try {
await run(`schema push --secret "secret"`, container);
} catch (e) {}

expect(logger.stderr).to.have.been.calledWith(
`${chalk.reset(await builtYargs.getHelp())}\n\n${chalk.red(
`No schema files (*.fsl) found in '${absoluteDirPath}'. Use '--dir' to specify a different directory, or create new .fsl files in this location.`,
)}`,
);
});

it("can push a schema without user input", async function () {
await run(`schema push --secret "secret" --no-input`, container);

Expand Down

0 comments on commit 82fd6d4

Please sign in to comment.