Skip to content

Commit

Permalink
warn user if no fsl files are found
Browse files Browse the repository at this point in the history
  • Loading branch information
henryfauna committed Dec 11, 2024
1 parent b3b82eb commit 89e575a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/commands/schema/push.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ts-check

import path from "path";

import { container } from "../../cli.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";
Expand All @@ -13,10 +15,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) {
logger.stdout(
`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
14 changes: 13 additions & 1 deletion test/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { setupTestContainer as setupContainer } from "../../src/config/setup-tes
import { reformatFSL } from "../../src/lib/schema.mjs";
import { buildUrl, f } from "../helpers.mjs";

describe("schema push", function () {
describe.only("schema push", function () {
const diffString =
"\u001b[1;34m* Modifying collection `Customer`\u001b[0m at collections.fsl:2:1:\n * Defined fields:\n\u001b[31m - drop field `.age`\u001b[0m\n\n";
let container, gatherFSL, fetch, logger, confirm;
Expand All @@ -31,6 +31,18 @@ describe("schema push", function () {
gatherFSL.resolves(fsl);
});

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

await run(`schema push --secret "secret"`, container);

expect(logger.stdout).to.have.been.calledWith(
sinon.match(
/^No schema files \(\*\.fsl\) found in '.*'\. 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 89e575a

Please sign in to comment.