Skip to content

Commit

Permalink
Merge branch 'v3' into better-child-exs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecooper authored Dec 18, 2024
2 parents b5af5c7 + 8e75abb commit 896b3ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 97 deletions.
13 changes: 1 addition & 12 deletions src/commands/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function createDatabaseSchema(argv) {
);
// hack to let us push schema to the local database
argv.secret = `secret:${argv.database}:admin`;
await pushSchema(argv);
await pushSchema({ ...argv, active: true, input: false });
logger.stderr(
colorize(
`[CreateDatabaseSchema] Schema for database '${argv.database}' created from directory '${argv.directory}'.`,
Expand Down Expand Up @@ -186,17 +186,6 @@ function buildLocalCommand(yargs) {
description:
"Path to a local directory containing .fsl files for the database. Valid only if --database is set.",
},
active: {
description:
"Apply the local schema to the database's active schema. Skips staging the schema. Use --no-active to disable.",
type: "boolean",
default: true,
},
input: {
description: "Prompt for input. Use --no-input to disable.",
default: true,
type: "boolean",
},
})
.check((argv) => {

Check warning on line 190 in src/commands/local.mjs

View workflow job for this annotation

GitHub Actions / lint

Arrow function has a complexity of 11. Maximum allowed is 10
if (argv.maxAttempts < 1) {
Expand Down
91 changes: 6 additions & 85 deletions test/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ describe("local command", () => {
simulateError,
startStub,
unpauseStub,
gatherFSL,
confirm;

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";
gatherFSL;

const fsl = [
{
Expand All @@ -45,7 +41,6 @@ describe("local command", () => {
logsStub = stub();
startStub = stub();
unpauseStub = stub();
confirm = container.resolve("confirm");

gatherFSL = container.resolve("gatherFSL");
gatherFSL.resolves(fsl);
Expand Down Expand Up @@ -174,107 +169,33 @@ Please pass a --host-port other than '8443'.",
const baseUrl = "http://0.0.0.0:8443/schema/1";
const { runQuery } = container.resolve("faunaClientV10");

confirm.resolves(true);
setupCreateContainerMocks();
runQuery.resolves({
data: JSON.stringify({ name: "Foo" }, null, 2),
});

// The first call pings the container, then the second creates the diff...
fetch
.onCall(1)
.resolves(
f({
version: 1728675598430000,
diff: diffString,
}),
)
.onCall(2)
.resolves(
f({
version: 1728675598430000,
}),
);

await run(`local --no-color ${args}`, container);

expect(gatherFSL).to.have.been.calledWith("bar");
expect(fetch).to.have.been.calledWith(`${baseUrl}/diff?staged=false`, {
method: "POST",
headers: { AUTHORIZATION: "Bearer secret:Foo:admin" },
body: reformatFSL(fsl),
});
expect(fetch).to.have.been.calledWith(
`${baseUrl}/update?staged=false&version=1728675598430000`,
{
method: "POST",
headers: { AUTHORIZATION: "Bearer secret:Foo:admin" },
body: reformatFSL(fsl),
},
);
const written = stderrStream.getWritten();
expect(written).to.contain(
"[CreateDatabaseSchema] Schema for database 'Foo' created from directory './bar'.",
fetch.onCall(1).resolves(
f({
version: 1728675598430000,
}),
);
});
});

[
"--database Foo --dir ./bar --no-active",
"--database Foo --directory ./bar --no-active",
"--database Foo --project-directory ./bar --no-active",
].forEach((args) => {
it(`Creates a staged schema without forcing if requested using ${args}`, async () => {
const baseUrl = "http://0.0.0.0:8443/schema/1";
const { runQuery } = container.resolve("faunaClientV10");

confirm.resolves(true);
setupCreateContainerMocks();
runQuery.resolves({
data: JSON.stringify({ name: "Foo" }, null, 2),
});

// The first call pings the container, then the second creates the diff...
fetch
.onCall(1)
.resolves(
f({
version: 1728675598430000,
diff: diffString,
}),
)
.onCall(2)
.resolves(
f({
version: 1728675598430000,
}),
);

await run(`local --no-color ${args}`, container);

expect(gatherFSL).to.have.been.calledWith("bar");
expect(fetch).to.have.been.calledWith(`${baseUrl}/diff?staged=true`, {
method: "POST",
headers: { AUTHORIZATION: "Bearer secret:Foo:admin" },
body: reformatFSL(fsl),
});
expect(fetch).to.have.been.calledWith(
`${baseUrl}/update?staged=true&version=1728675598430000`,
`${baseUrl}/update?force=true&staged=false`,
{
method: "POST",
headers: { AUTHORIZATION: "Bearer secret:Foo:admin" },
body: reformatFSL(fsl),
},
);
expect(logger.stdout).to.have.been.calledWith("Proposed diff:\n");
const written = stderrStream.getWritten();
expect(written).to.contain(
"[CreateDatabaseSchema] Schema for database 'Foo' created from directory './bar'.",
);
expect(confirm).to.have.been.calledWith(
sinon.match.has("message", "Stage the above changes?"),
);
expect(logger.stdout).to.have.been.calledWith(diffString);
});
});

Expand Down

0 comments on commit 896b3ce

Please sign in to comment.