Skip to content

Commit

Permalink
implemented multi environment support
Browse files Browse the repository at this point in the history
  • Loading branch information
pistachiobaby committed Jan 11, 2024
1 parent effb8b1 commit 1c82a57
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 83 deletions.
50 changes: 49 additions & 1 deletion spec/__support__/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ import type { App } from "../../src/services/app/app.js";
import { config } from "../../src/services/config/config.js";
import { loadCookie } from "../../src/services/http/auth.js";

/**
* A test Gadget app to use in tests with multi environment on.
*/
export const multiEnvironmentTestApp: App = Object.freeze({
id: 1,
slug: "test-multi-environment",
primaryDomain: "test.gadget.app",
hasSplitEnvironments: true,
multiEnvironmentEnabled: true,
environments: [
{
id: 1,
name: "development",
type: "development",
},
{
id: 2,
name: "production",
type: "production",
},
{
id: 3,
name: "cool-environment-development",
type: "development",
},
{
id: 4,
name: "other-environment-development",
type: "development",
},
],
});

/**
* A test Gadget app to use in tests.
*/
Expand All @@ -12,6 +45,19 @@ export const testApp: App = Object.freeze({
slug: "test",
primaryDomain: "test.gadget.app",
hasSplitEnvironments: true,
multiEnvironmentEnabled: false,
environments: [
{
id: 1,
name: "development",
type: "development",
},
{
id: 2,
name: "production",
type: "production",
},
],
});

/**
Expand All @@ -24,6 +70,8 @@ export const notTestApp: App = Object.freeze({
slug: "not-test",
primaryDomain: "not-test.gadget.app",
hasSplitEnvironments: false,
multiEnvironmentEnabled: false,
environments: [],
});

/**
Expand All @@ -38,6 +86,6 @@ export const nockTestApps = ({ optional = true, persist = true } = {}): void =>
expect(cookie).toBeTruthy();
return value === cookie;
})
.reply(200, [testApp, notTestApp])
.reply(200, [testApp, notTestApp, multiEnvironmentTestApp])
.persist(persist);
};
2 changes: 1 addition & 1 deletion spec/__support__/filesync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const makeSyncScenario = async ({
await localDir.loadIgnoreFile();

if (!localFiles[".gadget/sync.json"]) {
const syncJson: SyncJson = { app: testApp.slug, filesVersion: "1", mtime: Date.now() + 1 };
const syncJson: SyncJson = { app: testApp.slug, environment: "development", filesVersion: "1", mtime: Date.now() + 1 };
await fs.outputJSON(localDir.absolute(".gadget/sync.json"), syncJson, { spaces: 2 });
}
}
Expand Down
11 changes: 9 additions & 2 deletions spec/commands/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ describe("list", () => {
it("lists apps", async () => {
mock(user, "getUserOrLogin", () => ({ id: 1, email: "[email protected]", name: "Jane Doe" }));
mock(app, "getApps", () => [
{ id: 1, slug: "app-a", primaryDomain: "app-a.example.com", hasSplitEnvironments: true },
{ id: 2, slug: "app-b", primaryDomain: "cool-app.com", hasSplitEnvironments: true },
{
id: 1,
slug: "app-a",
primaryDomain: "app-a.example.com",
hasSplitEnvironments: true,
multiEnvironmentEnabled: true,
environments: [],
},
{ id: 2, slug: "app-b", primaryDomain: "cool-app.com", hasSplitEnvironments: true, multiEnvironmentEnabled: true, environments: [] },
]);

await command(ctx);
Expand Down
42 changes: 21 additions & 21 deletions spec/commands/sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"2\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"2\\"}",
"file.txt": "file v2",
},
}
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"3\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"3\\"}",
"file.txt": "file v3",
},
}
Expand Down Expand Up @@ -153,7 +153,7 @@ describe("sync", () => {
".gadget/": "",
".gadget/backup/": "",
".gadget/backup/file.txt": "file v3",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"4\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"4\\"}",
},
}
`);
Expand Down Expand Up @@ -197,7 +197,7 @@ describe("sync", () => {
".gadget/": "",
".gadget/backup/": "",
".gadget/backup/file.txt": "file v3",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"5\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"5\\"}",
"directory/": "",
},
}
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("sync", () => {
".gadget/backup/": "",
".gadget/backup/directory/": "",
".gadget/backup/file.txt": "file v3",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"6\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"6\\"}",
},
}
`);
Expand Down Expand Up @@ -316,7 +316,7 @@ describe("sync", () => {
".gadget/backup/": "",
".gadget/backup/directory/": "",
".gadget/backup/file.txt": "file v3",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"7\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"7\\"}",
"file1.txt": "file1.txt",
"file10.txt": "file10.txt",
"file2.txt": "file2.txt",
Expand Down Expand Up @@ -440,7 +440,7 @@ describe("sync", () => {
".gadget/backup/": "",
".gadget/backup/directory/": "",
".gadget/backup/file.txt": "file v3",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"7\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"7\\"}",
"file1.txt": "file1.txt",
"file10.txt": "file10.txt",
"file2.txt": "file2.txt",
Expand Down Expand Up @@ -576,7 +576,7 @@ describe("sync", () => {
".gadget/backup/": "",
".gadget/backup/directory/": "",
".gadget/backup/file.txt": "file v3",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"7\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"7\\"}",
"file.js": "file v2",
"file1.txt": "file1.txt",
"file10.txt": "file10.txt",
Expand Down Expand Up @@ -639,7 +639,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"2\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"2\\"}",
".ignore": "**/tmp",
},
}
Expand Down Expand Up @@ -680,7 +680,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"3\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"3\\"}",
".ignore": "**/tmp",
},
}
Expand Down Expand Up @@ -712,7 +712,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"2\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"2\\"}",
"file.txt": "file v2",
},
}
Expand Down Expand Up @@ -742,7 +742,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"3\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"3\\"}",
"file.txt": "file v3",
},
}
Expand Down Expand Up @@ -776,7 +776,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"4\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"4\\"}",
"renamed-file.txt": "file v3",
},
}
Expand Down Expand Up @@ -812,7 +812,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"5\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"5\\"}",
},
}
`);
Expand Down Expand Up @@ -852,7 +852,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"6\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"6\\"}",
"directory/": "",
},
}
Expand Down Expand Up @@ -897,7 +897,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"7\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"7\\"}",
"renamed-directory/": "",
},
}
Expand Down Expand Up @@ -944,7 +944,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"8\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"8\\"}",
},
}
`);
Expand Down Expand Up @@ -1020,7 +1020,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"9\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"9\\"}",
"file1.txt": "file1.txt",
"file10.txt": "file10.txt",
"file2.txt": "file2.txt",
Expand Down Expand Up @@ -1065,7 +1065,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"2\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"2\\"}",
"file.txt": "v10",
},
}
Expand Down Expand Up @@ -1131,7 +1131,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"1\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"1\\"}",
".ignore": "**/tmp",
"tmp/": "",
"tmp/file1.txt": "file1.txt",
Expand Down Expand Up @@ -1176,7 +1176,7 @@ describe("sync", () => {
},
"localDir": {
".gadget/": "",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"filesVersion\\":\\"2\\"}",
".gadget/sync.json": "{\\"app\\":\\"test\\",\\"environment\\":\\"development\\",\\"filesVersion\\":\\"2\\"}",
".ignore": "# watch it all",
},
}
Expand Down
1 change: 1 addition & 0 deletions spec/services/app/arg.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe("AppArg", () => {
"https://my-app--development.gadget.app",
"https://my-app.gadget.app/edit",
"https://my-app.gadget.app/edit/files/routes/GET.js",
"https://my-app.gadget.app/edit/cool-new-environment",
])("accepts %s", (value) => {
expect(AppArg(value, "--app")).toEqual("my-app");
});
Expand Down
1 change: 1 addition & 0 deletions spec/services/app/edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("Edit", () => {
loginTestUser();
ctx = makeContext();
ctx.app = testApp;
ctx.environment = "development";
});

it("retries queries when it receives a 500", async () => {
Expand Down
Loading

0 comments on commit 1c82a57

Please sign in to comment.