Skip to content

Commit

Permalink
fix schema status confirmation prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Oct 29, 2024
1 parent 09bcb9b commit 27e809f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/commands/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ async function doPush(argv) {
const gatherFSL = container.resolve("gatherFSL");
const fsl = reformatFSL(await gatherFSL(argv.dir));

const isStagedPush = !argv.active;

if (!argv.input) {
const params = new URLSearchParams({
force: "true",
Expand Down Expand Up @@ -41,13 +43,13 @@ async function doPush(argv) {
method: "POST",
});

let message = "Accept and push changes?";
let message = isStagedPush ? "Stage the above changes?" : "Push the above changes?";
if (response.diff) {
logger.stdout(`Proposed diff:\n`);
logger.stdout(response.diff);
} else {
logger.stdout("No logical changes.");
message = "Push file contents anyway?";
message = isStagedPush ? "Stage the file contents anyway?" : "Push the file contents anyway?";
}
const confirm = container.resolve("confirm");
const confirmed = await confirm({
Expand Down
56 changes: 54 additions & 2 deletions test/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ describe("schema push", function () {

expect(logger.stderr).to.not.be.called;
expect(logger.stdout).to.have.been.calledWith("Proposed diff:\n");
expect(confirm).to.have.been.calledWith(
sinon.match.has("message", "Stage the above changes?"),
);
expect(logger.stdout).to.have.been.calledWith(diffString);
});

Expand Down Expand Up @@ -146,6 +149,9 @@ describe("schema push", function () {

expect(logger.stderr).to.not.be.called;
expect(logger.stdout).to.have.been.calledWith("Proposed diff:\n");
expect(confirm).to.have.been.calledWith(
sinon.match.has("message", "Push the above changes?"),
);
expect(logger.stdout).to.have.been.calledWith(diffString);
});

Expand Down Expand Up @@ -192,7 +198,7 @@ describe("schema push", function () {
expect(gatherFSL).to.have.been.calledWith("/absolute/path/elsewhere");
});

it("warns when attempting to push an empty diff", async function () {
it("warns when attempting to stage an empty diff", async function () {
// user accepts the changes in the interactive prompt
confirm.resolves(true);

Expand Down Expand Up @@ -234,7 +240,53 @@ describe("schema push", function () {
expect(logger.stderr).to.not.be.called;
expect(logger.stdout).to.have.been.calledWith("No logical changes.");
expect(confirm).to.have.been.calledWith(
sinon.match.has("message", "Push file contents anyway?"),
sinon.match.has("message", "Stage the file contents anyway?"),
);
});

it("warns when attempting to push an empty diff", async function () {
// user accepts the changes in the interactive prompt
confirm.resolves(true);

fetch.onCall(0).resolves(
f({
// this is the version we provide when we mutate the resource
version: 1728675598430000,
// note: no diff
}),
);

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

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
force: "true",
staged: "false",
color: "ansi",
}),
{
method: "POST",
headers: { AUTHORIZATION: "Bearer secret" },
body: reformatFSL(fsl),
},
);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/update", {
version: "1728675598430000",
staged: "false",
}),
{
method: "POST",
headers: { AUTHORIZATION: "Bearer secret" },
body: reformatFSL(fsl),
},
);

expect(logger.stderr).to.not.be.called;
expect(logger.stdout).to.have.been.calledWith("No logical changes.");
expect(confirm).to.have.been.calledWith(
sinon.match.has("message", "Push the file contents anyway?"),
);
});

Expand Down

0 comments on commit 27e809f

Please sign in to comment.