Skip to content

Commit 172bf50

Browse files
author
Observable User
committed
new test for when repo doesnt match
1 parent fede926 commit 172bf50

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

test/deploy-test.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {ObservableApiClientOptions, PostDeployUploadedRequest} from "../src
1414
import type {GetCurrentUserResponse} from "../src/observableApiClient.js";
1515
import {ObservableApiClient} from "../src/observableApiClient.js";
1616
import type {DeployConfig} from "../src/observableApiConfig.js";
17-
import {stripColor} from "../src/tty.js";
17+
import {link, stripColor} from "../src/tty.js";
1818
import {MockAuthEffects} from "./mocks/authEffects.js";
1919
import {TestClackEffects} from "./mocks/clack.js";
2020
import {MockConfigEffects} from "./mocks/configEffects.js";
@@ -207,7 +207,7 @@ describe("deploy", () => {
207207
describe("in isolated directory with git repo", () => {
208208
mockIsolatedDirectory({git: true});
209209

210-
it("fails continuous deployment if repo has no GitHub remote", async () => {
210+
it("fails cloud build if repo has no GitHub remote", async () => {
211211
getCurrentObservableApi()
212212
.handleGetCurrentUser()
213213
.handleGetWorkspaceProjects({
@@ -234,7 +234,39 @@ describe("deploy", () => {
234234
effects.close();
235235
});
236236

237-
it("starts cloud build when continuous deployment is enabled and repo is valid", async () => {
237+
it("fails cloud build if repo doesn’t match", async () => {
238+
getCurrentObservableApi()
239+
.handleGetCurrentUser()
240+
.handleGetProject({
241+
...DEPLOY_CONFIG,
242+
source: {
243+
provider: "github",
244+
provider_id: "123:456",
245+
url: "https://github.com/observablehq/test.git",
246+
branch: "main"
247+
},
248+
latestCreatedDeployId: null
249+
})
250+
.handleGetRepository({ownerName: "observablehq", repoName: "wrongrepo", provider_id: "000:001"})
251+
.start();
252+
const effects = new MockDeployEffects({deployConfig: {...DEPLOY_CONFIG, continuousDeployment: true}});
253+
254+
await (await open("readme.md", "a")).close();
255+
await promisify(exec)(
256+
"git add . && git commit -m 'initial' && git remote add origin [email protected]:observablehq/wrongrepo.git"
257+
);
258+
259+
try {
260+
await deploy(TEST_OPTIONS, effects);
261+
assert.fail("expected error");
262+
} catch (error) {
263+
CliError.assert(error, {message: `Configured repository does not match local repository; check build settings on ${link(`https://observablehq.com/projects/@${DEPLOY_CONFIG.workspaceLogin}/${DEPLOY_CONFIG.projectSlug}/settings`)}`});
264+
}
265+
266+
effects.close();
267+
});
268+
269+
it("starts cloud build when continuous deployment is enabled for new project and repo is valid", async () => {
238270
const deployId = "deploy123";
239271
getCurrentObservableApi()
240272
.handleGetCurrentUser()
@@ -282,6 +314,7 @@ describe("deploy", () => {
282314
},
283315
latestCreatedDeployId: null
284316
})
317+
.handleGetRepository({useProviderId: false})
285318
.handleGetRepository({useProviderId: true})
286319
.handlePostProjectBuild()
287320
.handleGetProject({
@@ -297,9 +330,6 @@ describe("deploy", () => {
297330
.handleGetDeploy({deployId, deployStatus: "uploaded"})
298331
.start();
299332
const effects = new MockDeployEffects({deployConfig: {...DEPLOY_CONFIG, continuousDeployment: true}});
300-
effects.clack.inputs.push(
301-
"bi" // Which app do you want to use?
302-
);
303333

304334
await (await open("readme.md", "a")).close();
305335
await promisify(exec)(
@@ -315,7 +345,7 @@ describe("deploy", () => {
315345
describe("in isolated directory without git repo", () => {
316346
mockIsolatedDirectory({git: false});
317347

318-
it("fails continuous deployment if not in a git repo", async () => {
348+
it("fails cloud build if not in a git repo", async () => {
319349
getCurrentObservableApi()
320350
.handleGetCurrentUser()
321351
.handleGetWorkspaceProjects({

test/mocks/observableApi.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,19 @@ class ObservableApiMock {
437437
return this;
438438
}
439439

440-
handleGetRepository({status = 200, useProviderId = false}: {status?: number; useProviderId?: boolean} = {}) {
440+
handleGetRepository({
441+
status = 200,
442+
ownerName = "observablehq",
443+
repoName = "test",
444+
provider_id = "123:456",
445+
useProviderId = false
446+
}: {status?: number; ownerName?: string; repoName?: string; provider_id?: string; useProviderId?: boolean} = {}) {
441447
const response =
442448
status === 200
443449
? JSON.stringify({
444450
provider: "github",
445-
provider_id: "123:456",
446-
url: "https://github.com/observablehq/test.git",
451+
provider_id,
452+
url: `https://github.com/${ownerName}/${repoName}.git`,
447453
default_branch: "main",
448454
name: "test",
449455
linked_projects: []
@@ -455,7 +461,7 @@ class ObservableApiMock {
455461
this._handlers.push((pool) =>
456462
pool
457463
.intercept({
458-
path: `/cli/github/repository?provider_id=${encodeURIComponent("123:456")}`,
464+
path: `/cli/github/repository?provider_id=${encodeURIComponent(provider_id)}`,
459465
headers: headersMatcher(headers)
460466
})
461467
.reply(status, response, {headers: {"content-type": "application/json"}})
@@ -464,7 +470,10 @@ class ObservableApiMock {
464470
// version that accepts owner & repo
465471
this._handlers.push((pool) =>
466472
pool
467-
.intercept({path: "/cli/github/repository?owner=observablehq&repo=test", headers: headersMatcher(headers)})
473+
.intercept({
474+
path: `/cli/github/repository?owner=${ownerName}&repo=${repoName}`,
475+
headers: headersMatcher(headers)
476+
})
468477
.reply(status, response, {headers: {"content-type": "application/json"}})
469478
);
470479
}

0 commit comments

Comments
 (0)