Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henryfauna committed Dec 12, 2024
1 parent 127f1e6 commit feec095
Showing 1 changed file with 44 additions and 27 deletions.
71 changes: 44 additions & 27 deletions test/schema/status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

import { run } from "../../src/cli.mjs";
import { setupTestContainer as setupContainer } from "../../src/config/setup-test-container.mjs";
Expand Down Expand Up @@ -110,11 +110,11 @@ describe("schema status", function () {
}),
{ ...commonFetchParams, method: "POST", body: new FormData() },
);
expect(logger.stdout).to.have.been.calledWith(`No staged changes.`);

const absoluteDirPath = path.resolve(".");
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("none")}`,
);
expect(logger.stdout).to.have.been.calledWith(
sinon.match(/^Local changes: .*no schema files found in.*\n$/),
`\nNo local changes. No schema files found in '${absoluteDirPath}'.\n`,
);
});

Expand Down Expand Up @@ -151,12 +151,8 @@ describe("schema status", function () {
}),
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
);
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("none")}`,
);
expect(logger.stdout).to.have.been.calledWith(
`Local changes: ${chalk.bold("none")}\n`,
);
expect(logger.stdout).to.have.been.calledWith("No staged changes.");
expect(logger.stdout).to.have.been.calledWith("\nNo local changes.\n");
});

it("fetches the current status when there are only local changes", async function () {
Expand Down Expand Up @@ -195,18 +191,23 @@ describe("schema status", function () {
}),
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
);
expect(logger.stdout).to.have.been.calledWith("No staged changes.");

expect(logger.stdout).to.have.been.calledWith("\nLocal changes:");
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("none")}`,
" (use `fauna schema diff` to display local changes)",
);
expect(logger.stdout).to.have.been.calledWith(`Local changes:\n`);
expect(logger.stdout).to.have.been.calledWith(
` * Adding collection \`NewCollection\` to collections.fsl:2:1\n * Modifying collection \`OrderItem\` at collections.fsl:125:1\n * Modifying function \`createOrUpdateCartItem\` at functions.fsl:2:1\n `,
" (use `fauna schema push` to stage local changes)",
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema diff` to display local changes)",
` * Adding collection \`NewCollection\` to collections.fsl:2:1`,
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema push` to stage local changes)",
" * Modifying collection `OrderItem` at collections.fsl:125:1",
);
expect(logger.stdout).to.have.been.calledWith(
" * Modifying function `createOrUpdateCartItem` at functions.fsl:2:1",
);
expect(logger.stderr).not.to.have.been.called;
});
Expand Down Expand Up @@ -246,13 +247,19 @@ describe("schema status", function () {
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
);
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("ready")}`,
`Staged changes are ${chalk.bold("ready")}:`,
);
expect(logger.stdout).to.have.been.calledWith(
" (use `fauna schema commit` to commit staged changes)",
);
expect(logger.stdout).to.have.been.calledWith(
" " + summaryDiff.split("\n")[0],
);
expect(logger.stdout).to.have.been.calledWith(
`Local changes: ${chalk.bold("none")}\n`,
" " + summaryDiff.split("\n")[1],
);
expect(logger.stdout).to.have.been.calledWith(
summaryDiff.split("\n").join("\n "),
" " + summaryDiff.split("\n")[2],
);
expect(logger.stderr).not.to.have.been.called;
});
Expand Down Expand Up @@ -293,22 +300,32 @@ describe("schema status", function () {
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
);
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("ready")}`,
`Staged changes are ${chalk.bold("ready")}:`,
);
expect(logger.stdout).to.have.been.calledWith(
" (use `fauna schema commit` to commit staged changes)",
);
expect(logger.stdout).to.have.been.calledWith(
" " + summaryDiff.split("\n")[0],
);
expect(logger.stdout).to.have.been.calledWith(
" " + summaryDiff.split("\n")[1],
);
expect(logger.stdout).to.have.been.calledWith(
" " + summaryDiff.split("\n")[2],
);
expect(logger.stdout).to.have.been.calledWith(`Staged changes:\n`);
expect(logger.stdout).to.have.been.calledWith(`Local changes:\n`);
expect(logger.stdout).to.have.been.calledWith(`\nLocal changes:`);
expect(logger.stdout).to.have.been.calledWith(
summaryDiff.split("\n").join("\n "),
" (use `fauna schema diff` to display local changes)",
);
expect(logger.stdout).to.have.been.calledWith(
" * Adding function `newFunction` to functions.fsl:1:1\n" +
" * Modifying function `createOrUpdateCartItem` at functions.fsl:5:1\n ",
" (use `fauna schema push` to stage local changes)",
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema diff` to display local changes)",
" * Adding function `newFunction` to functions.fsl:1:1",
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema push` to stage local changes)",
" * Modifying function `createOrUpdateCartItem` at functions.fsl:5:1",
);
expect(logger.stderr).not.to.have.been.called;
});
Expand Down

0 comments on commit feec095

Please sign in to comment.