Skip to content

Commit

Permalink
run prettier, eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Oct 25, 2024
1 parent ea57eee commit a0a4e60
Showing 1 changed file with 134 additions and 80 deletions.
214 changes: 134 additions & 80 deletions test/schema/status.mjs
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
import chalk from "chalk";
import { expect } from "chai";
//@ts-check

import { f, commonFetchParams, buildUrl } from "../helpers.mjs";
import { expect } from "chai";
import chalk from "chalk";

import { run } from "../../src/cli.mjs";
import { setupTestContainer as setupContainer } from "../../src/config/setup-test-container.mjs";
import { buildUrl, commonFetchParams, f } from "../helpers.mjs";

describe("schema status", function () {
let container, fetch, logger;

let summaryDiff = '\x1B[1;34m* Adding collection `NewCollection`\x1B[0m to collections.fsl:2:1\n' +
'\x1B[1;34m* Modifying collection `OrderItem`\x1B[0m at collections.fsl:125:1\n' +
'\x1B[1;34m* Modifying function `createOrUpdateCartItem`\x1B[0m at functions.fsl:2:1\n';

let textDiff = '\x1B[1mcollections.fsl\x1B[22m\n' +
'\x1B[36m@ line 1 to 7\x1B[0m\n' +
'\n' +
'\x1B[32m+ collection NewCollection {\x1B[0m\n' +
'\x1B[32m+ }\x1B[0m\n' +
'\x1B[32m+\x1B[0m\n' +
' collection Customer {\n' +
' name: String\n' +
' email: String\n' +
'\x1B[36m@ line 134 to 139\x1B[0m\n' +
' terms [.order]\n' +
' values [.product, .quantity]\n' +
' }\n' +
'\x1B[31m-\x1B[0m\n' +
'\x1B[31m- index byOrderAndProduct {\x1B[0m\n' +
'\x1B[31m- terms [.order, .product]\x1B[0m\n' +
'\x1B[31m- }\x1B[0m\n' +
' }\n' +
'\n' +
'\n' +
'\n' +
'\x1B[1mfunctions.fsl\x1B[22m\n' +
'\x1B[36m@ line 30 to 35\x1B[0m\n' +
' if (product!.stock < quantity) {\n' +
let summaryDiff =
"\x1B[1;34m* Adding collection `NewCollection`\x1B[0m to collections.fsl:2:1\n" +
"\x1B[1;34m* Modifying collection `OrderItem`\x1B[0m at collections.fsl:125:1\n" +
"\x1B[1;34m* Modifying function `createOrUpdateCartItem`\x1B[0m at functions.fsl:2:1\n";

let textDiff =
"\x1B[1mcollections.fsl\x1B[22m\n" +
"\x1B[36m@ line 1 to 7\x1B[0m\n" +
"\n" +
"\x1B[32m+ collection NewCollection {\x1B[0m\n" +
"\x1B[32m+ }\x1B[0m\n" +
"\x1B[32m+\x1B[0m\n" +
" collection Customer {\n" +
" name: String\n" +
" email: String\n" +
"\x1B[36m@ line 134 to 139\x1B[0m\n" +
" terms [.order]\n" +
" values [.product, .quantity]\n" +
" }\n" +
"\x1B[31m-\x1B[0m\n" +
"\x1B[31m- index byOrderAndProduct {\x1B[0m\n" +
"\x1B[31m- terms [.order, .product]\x1B[0m\n" +
"\x1B[31m- }\x1B[0m\n" +
" }\n" +
"\n" +
"\n" +
"\n" +
"\x1B[1mfunctions.fsl\x1B[22m\n" +
"\x1B[36m@ line 30 to 35\x1B[0m\n" +
" if (product!.stock < quantity) {\n" +
' abort("Product does not have the requested quantity in stock.")\n' +
' }\n' +
'\x1B[31m-\x1B[0m\n' +
'\x1B[31m- // Attempt to find an existing order item for the order, product pair.\x1B[0m\n' +
'\x1B[31m- // There is a unique constraint on [.order, .product] so this will return at most one result.\x1B[0m\n' +
'\x1B[31m- let orderItem = OrderItem.byOrderAndProduct(customer!.cart, product).first()\x1B[0m\n' +
'\x1B[31m-\x1B[0m\n' +
'\x1B[31m- if (orderItem == null) {\x1B[0m\n' +
'\x1B[31m- // If the order item does not exist, create a new one.\x1B[0m\n' +
'\x1B[31m- OrderItem.create({\x1B[0m\n' +
'\x1B[31m- order: Order(customer!.cart!.id),\x1B[0m\n' +
'\x1B[31m- product: product,\x1B[0m\n' +
'\x1B[31m- quantity: quantity,\x1B[0m\n' +
'\x1B[31m- })\x1B[0m\n' +
'\x1B[31m- } else {\x1B[0m\n' +
'\x1B[31m- // If the order item exists, update the quantity.\x1B[0m\n' +
'\x1B[31m- orderItem!.update({ quantity: quantity })\x1B[0m\n' +
'\x1B[31m- }\x1B[0m\n' +
' }\n' +
'\n' +
' function getOrCreateCart(id) {\n';
" }\n" +
"\x1B[31m-\x1B[0m\n" +
"\x1B[31m- // Attempt to find an existing order item for the order, product pair.\x1B[0m\n" +
"\x1B[31m- // There is a unique constraint on [.order, .product] so this will return at most one result.\x1B[0m\n" +
"\x1B[31m- let orderItem = OrderItem.byOrderAndProduct(customer!.cart, product).first()\x1B[0m\n" +
"\x1B[31m-\x1B[0m\n" +
"\x1B[31m- if (orderItem == null) {\x1B[0m\n" +
"\x1B[31m- // If the order item does not exist, create a new one.\x1B[0m\n" +
"\x1B[31m- OrderItem.create({\x1B[0m\n" +
"\x1B[31m- order: Order(customer!.cart!.id),\x1B[0m\n" +
"\x1B[31m- product: product,\x1B[0m\n" +
"\x1B[31m- quantity: quantity,\x1B[0m\n" +
"\x1B[31m- })\x1B[0m\n" +
"\x1B[31m- } else {\x1B[0m\n" +
"\x1B[31m- // If the order item exists, update the quantity.\x1B[0m\n" +
"\x1B[31m- orderItem!.update({ quantity: quantity })\x1B[0m\n" +
"\x1B[31m- }\x1B[0m\n" +
" }\n" +
"\n" +
" function getOrCreateCart(id) {\n";

beforeEach(() => {
container = setupContainer();
Expand Down Expand Up @@ -89,11 +92,19 @@ describe("schema status", function () {
commonFetchParams,
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", { diff: "summary", staged: "true", version: "0" }),
{ ...commonFetchParams, method: "POST", body: new FormData() }
buildUrl("/schema/1/validate", {
diff: "summary",
staged: "true",
version: "0",
}),
{ ...commonFetchParams, method: "POST", body: new FormData() },
);
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(`Staged changes: ${chalk.bold("none")}`)
expect(logger.stdout).to.have.been.calledWith(`Local changes: ${chalk.bold("none")}\n`)
});

it("fetches the current status when there are only local changes", async function () {
Expand All @@ -109,9 +120,10 @@ describe("schema status", function () {
fetch.onCall(1).resolves(
f({
version: 0,
diff: '* 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'
diff:
"* 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",
}),
);

Expand All @@ -122,14 +134,26 @@ describe("schema status", function () {
commonFetchParams,
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", { diff: "summary", staged: "true", version: "0" }),
{ ...commonFetchParams, method: "POST", body: new FormData() }
buildUrl("/schema/1/validate", {
diff: "summary",
staged: "true",
version: "0",
}),
{ ...commonFetchParams, method: "POST", body: new FormData() },
);
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("none")}`,
);
expect(logger.stdout).to.have.been.calledWith(`Staged changes: ${chalk.bold("none")}`);
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 `);
expect(logger.stdout).to.have.been.calledWith("(use `fauna schema diff` to display local changes)");
expect(logger.stdout).to.have.been.calledWith("(use `fauna schema push` to stage local changes)");
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 `,
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema diff` to display local changes)",
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema push` to stage local changes)",
);
expect(logger.stderr).not.to.have.been.called;
});

Expand Down Expand Up @@ -158,16 +182,30 @@ describe("schema status", function () {
);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", { diff: "summary", staged: "true", version: "0" }),
{ ...commonFetchParams, method: "POST", body: new FormData() }
buildUrl("/schema/1/validate", {
diff: "summary",
staged: "true",
version: "0",
}),
{ ...commonFetchParams, method: "POST", body: new FormData() },
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", { diff: "summary", staged: "true", version: "0" }),
{ ...commonFetchParams, method: "POST", body: new FormData() }
buildUrl("/schema/1/validate", {
diff: "summary",
staged: "true",
version: "0",
}),
{ ...commonFetchParams, method: "POST", body: new FormData() },
);
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("ready")}`,
);
expect(logger.stdout).to.have.been.calledWith(
`Local changes: ${chalk.bold("none")}\n`,
);
expect(logger.stdout).to.have.been.calledWith(
summaryDiff.split("\n").join("\n "),
);
expect(logger.stdout).to.have.been.calledWith(`Staged changes: ${chalk.bold("ready")}`);
expect(logger.stdout).to.have.been.calledWith(`Local changes: ${chalk.bold("none")}\n`);
expect(logger.stdout).to.have.been.calledWith(summaryDiff.split("\n").join("\n "))
expect(logger.stderr).not.to.have.been.called;
});

Expand All @@ -184,8 +222,9 @@ describe("schema status", function () {
fetch.onCall(1).resolves(
f({
version: 0,
diff: '* Adding function `newFunction` to functions.fsl:1:1\n' +
'* Modifying function `createOrUpdateCartItem` at functions.fsl:5:1\n'
diff:
"* Adding function `newFunction` to functions.fsl:1:1\n" +
"* Modifying function `createOrUpdateCartItem` at functions.fsl:5:1\n",
}),
);

Expand All @@ -196,16 +235,31 @@ describe("schema status", function () {
commonFetchParams,
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/validate", { diff: "summary", staged: "true", version: "0" }),
{ ...commonFetchParams, method: "POST", body: new FormData() }
buildUrl("/schema/1/validate", {
diff: "summary",
staged: "true",
version: "0",
}),
{ ...commonFetchParams, method: "POST", body: new FormData() },
);
expect(logger.stdout).to.have.been.calledWith(
`Staged changes: ${chalk.bold("ready")}`,
);
expect(logger.stdout).to.have.been.calledWith(`Staged changes: ${chalk.bold("ready")}`);
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(summaryDiff.split("\n").join("\n "))
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 ');
expect(logger.stdout).to.have.been.calledWith("(use `fauna schema diff` to display local changes)");
expect(logger.stdout).to.have.been.calledWith("(use `fauna schema push` to stage local changes)");
expect(logger.stdout).to.have.been.calledWith(
summaryDiff.split("\n").join("\n "),
);
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 ",
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema diff` to display local changes)",
);
expect(logger.stdout).to.have.been.calledWith(
"(use `fauna schema push` to stage local changes)",
);
expect(logger.stderr).not.to.have.been.called;
});

Expand Down

0 comments on commit a0a4e60

Please sign in to comment.