Skip to content

Commit

Permalink
Update usage of the schema API for push, status, and diff (#502)
Browse files Browse the repository at this point in the history
Co-authored-by: E. Cooper <[email protected]>
  • Loading branch information
ptpaterson and ecooper authored Dec 11, 2024
1 parent 79681b6 commit b3b82eb
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/commands/schema/diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function doDiff(argv) {
} else {
const { diff } = await makeFaunaRequest({
argv,
path: "/schema/1/validate",
path: "/schema/1/diff",
params: buildValidateParams(argv, version),
body: files,
method: "POST",
Expand Down
6 changes: 2 additions & 4 deletions src/commands/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ async function doPush(argv) {
secret,
});
} else {
// Confirm diff, then push it. `force` is set on `validate` so we don't
// need to pass the last known schema version through.
// Confirm diff, then push it.
const params = new URLSearchParams({
force: "true",
staged: argv.active ? "false" : "true",
});

const response = await makeFaunaRequest({
argv,
path: "/schema/1/validate",
path: "/schema/1/diff",
params,
body: fsl,
method: "POST",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/schema/status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function doStatus(argv) {

const validationResponse = await makeFaunaRequest({
argv,
path: "/schema/1/validate",
path: "/schema/1/diff",
params,
method: "POST",
body: fsl,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/db.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CommandError } from "./command-helpers.mjs";
import { retryInvalidCredsOnce } from "./fauna-client.mjs";

function buildParamsString({ argv, params, path }) {
const routesWithColor = ["/schema/1/staged/status", "/schema/1/validate"];
const routesWithColor = ["/schema/1/staged/status", "/schema/1/diff"];
if (params && argv.color && routesWithColor.includes(path))
params.set("color", "ansi");
if (params && params.sort) params.sort();
Expand Down
8 changes: 4 additions & 4 deletions test/schema/diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("schema diff", function () {
{ ...commonFetchParams, method: "GET" },
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
color: "ansi",
diff: "semantic",
force: "true",
Expand All @@ -72,7 +72,7 @@ describe("schema diff", function () {
{ ...commonFetchParams, method: "GET" },
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
color: "ansi",
diff: "semantic",
force: "true",
Expand All @@ -99,7 +99,7 @@ describe("schema diff", function () {
method: "GET",
});
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
force: "true",
staged: "true",
diff: "semantic",
Expand All @@ -125,7 +125,7 @@ describe("schema diff", function () {
{ ...commonFetchParams, method: "GET" },
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
force: "true",
color: "ansi",
staged: "true",
Expand Down
15 changes: 5 additions & 10 deletions test/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ describe("schema push", function () {
await run(`schema push --secret "secret"`, container);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
force: "true",
buildUrl("/schema/1/diff", {
staged: "true",
color: "ansi",
}),
Expand Down Expand Up @@ -125,8 +124,7 @@ describe("schema push", function () {
await run(`schema push --secret "secret" --active`, container);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
force: "true",
buildUrl("/schema/1/diff", {
staged: "false",
color: "ansi",
}),
Expand Down Expand Up @@ -172,8 +170,7 @@ describe("schema push", function () {
await run(`schema push --secret "secret"`, container);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
force: "true",
buildUrl("/schema/1/diff", {
staged: "true",
color: "ansi",
}),
Expand Down Expand Up @@ -215,8 +212,7 @@ describe("schema push", function () {
await run(`schema push --secret "secret"`, container);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
force: "true",
buildUrl("/schema/1/diff", {
staged: "true",
color: "ansi",
}),
Expand Down Expand Up @@ -261,8 +257,7 @@ describe("schema push", function () {
await run(`schema push --secret "secret" --active`, container);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
force: "true",
buildUrl("/schema/1/diff", {
staged: "false",
color: "ansi",
}),
Expand Down
8 changes: 4 additions & 4 deletions test/schema/status.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("schema status", function () {
commonFetchParams,
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
diff: "summary",
staged: "true",
version: "0",
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("schema status", function () {
commonFetchParams,
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
diff: "summary",
staged: "true",
version: "0",
Expand Down Expand Up @@ -184,7 +184,7 @@ describe("schema status", function () {
);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
diff: "summary",
staged: "true",
version: "0",
Expand Down Expand Up @@ -230,7 +230,7 @@ describe("schema status", function () {
commonFetchParams,
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", {
buildUrl("/schema/1/diff", {
diff: "summary",
staged: "true",
version: "0",
Expand Down

0 comments on commit b3b82eb

Please sign in to comment.