Skip to content

Commit eeeea45

Browse files
committed
test(app): deduplicate identity conflict setup
1 parent f800c05 commit eeeea45

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

packages/app/tests/docker-git/create-project-identity-conflict.test.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,34 @@ const makeCommand = (
121121
waitForClone: false
122122
})
123123

124+
const makeConflictContext = (
125+
root: string,
126+
path: Path.Path,
127+
force: boolean
128+
) => {
129+
const outDir = path.join(root, "candidate")
130+
const existingDir = path.join(root, "existing")
131+
return {
132+
outDir,
133+
existingDir,
134+
existingConfigPath: path.join(existingDir, "docker-git.json"),
135+
command: makeCommand(root, outDir, force)
136+
}
137+
}
138+
139+
const mockProjectIndex = (
140+
root: string,
141+
path: Path.Path,
142+
configPaths: ReadonlyArray<string>
143+
): void => {
144+
loadProjectIndexMock.mockReturnValue(
145+
Effect.succeed({
146+
projectsRoot: path.join(root, ".docker-git"),
147+
configPaths
148+
})
149+
)
150+
}
151+
124152
describe("createProject docker identity guard", () => {
125153
beforeEach(() => {
126154
loadProjectIndexMock.mockReset()
@@ -138,17 +166,9 @@ describe("createProject docker identity guard", () => {
138166
withTempDir((root) =>
139167
Effect.gen(function*(_) {
140168
const path = yield* _(Path.Path)
141-
const outDir = path.join(root, "candidate")
142-
const existingDir = path.join(root, "existing")
143-
const existingConfigPath = path.join(existingDir, "docker-git.json")
144-
const command = makeCommand(root, outDir, false)
145-
146-
loadProjectIndexMock.mockReturnValue(
147-
Effect.succeed({
148-
projectsRoot: path.join(root, ".docker-git"),
149-
configPaths: [existingConfigPath]
150-
})
151-
)
169+
const { command, existingConfigPath, existingDir, outDir } = makeConflictContext(root, path, false)
170+
171+
mockProjectIndex(root, path, [existingConfigPath])
152172
loadProjectStatusMock.mockImplementation((configPath: string) =>
153173
Effect.succeed(
154174
makeStatus(
@@ -187,17 +207,9 @@ describe("createProject docker identity guard", () => {
187207
withTempDir((root) =>
188208
Effect.gen(function*(_) {
189209
const path = yield* _(Path.Path)
190-
const outDir = path.join(root, "candidate")
191-
const existingDir = path.join(root, "existing")
192-
const existingConfigPath = path.join(existingDir, "docker-git.json")
193-
const command = makeCommand(root, outDir, true)
210+
const { command, existingConfigPath, existingDir } = makeConflictContext(root, path, true)
194211

195-
loadProjectIndexMock.mockReturnValue(
196-
Effect.succeed({
197-
projectsRoot: path.join(root, ".docker-git"),
198-
configPaths: [existingConfigPath]
199-
})
200-
)
212+
mockProjectIndex(root, path, [existingConfigPath])
201213
loadProjectStatusMock.mockReturnValue(
202214
Effect.succeed(makeStatus(existingDir, root))
203215
)
@@ -224,12 +236,7 @@ describe("createProject docker identity guard", () => {
224236
const configPath = path.join(outDir, "docker-git.json")
225237
const command = makeCommand(root, outDir, true)
226238

227-
loadProjectIndexMock.mockReturnValue(
228-
Effect.succeed({
229-
projectsRoot: path.join(root, ".docker-git"),
230-
configPaths: [configPath]
231-
})
232-
)
239+
mockProjectIndex(root, path, [configPath])
233240
loadProjectStatusMock.mockReturnValue(
234241
Effect.succeed(makeStatus(outDir, root))
235242
)

0 commit comments

Comments
 (0)