2023-10-23 23:16:24 +02:00
|
|
|
import test from "node:test"
|
|
|
|
import assert from "node:assert/strict"
|
|
|
|
import crypto from "node:crypto"
|
2022-09-22 16:16:21 +02:00
|
|
|
|
2023-10-23 23:16:24 +02:00
|
|
|
import sinon from "sinon"
|
2022-04-23 18:41:14 +02:00
|
|
|
|
2023-10-23 23:16:24 +02:00
|
|
|
import { Challenge } from "../Challenge.js"
|
|
|
|
import { GitAffected } from "../GitAffected.js"
|
|
|
|
import { Solution } from "../Solution.js"
|
|
|
|
import { parseCommandOutput } from "../../utils/parseCommandOutput.js"
|
2021-12-07 12:11:54 +01:00
|
|
|
|
2022-09-22 16:16:21 +02:00
|
|
|
const gitAffected = new GitAffected()
|
2021-12-07 12:11:54 +01:00
|
|
|
|
2023-10-23 23:16:24 +02:00
|
|
|
await test("services/GitAffected", async (t) => {
|
2022-09-22 16:16:21 +02:00
|
|
|
t.afterEach(() => {
|
|
|
|
sinon.restore()
|
|
|
|
})
|
|
|
|
|
|
|
|
t.beforeEach(() => {
|
2023-10-23 23:16:24 +02:00
|
|
|
sinon.stub(crypto, "randomUUID").value(() => {
|
|
|
|
return "uuid"
|
2022-09-22 16:16:21 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-10-23 23:16:24 +02:00
|
|
|
await t.test("parseCommandOutput", async (t) => {
|
|
|
|
await t.test("returns the right output array", async () => {
|
|
|
|
assert.deepStrictEqual(parseCommandOutput("1.txt\n 2.txt "), [
|
|
|
|
"1.txt",
|
|
|
|
"2.txt",
|
2023-07-20 22:00:11 +02:00
|
|
|
])
|
2022-04-23 18:41:14 +02:00
|
|
|
})
|
2021-12-07 12:11:54 +01:00
|
|
|
})
|
|
|
|
|
2023-10-23 23:16:24 +02:00
|
|
|
await t.test("getAffectedSolutionsFromFiles", async (t) => {
|
|
|
|
await t.test("returns the affected solutions", async () => {
|
2022-04-23 18:41:14 +02:00
|
|
|
const files = [
|
2023-10-23 23:16:24 +02:00
|
|
|
"challenges/hello-world/solutions/javascript/function/solution.js",
|
|
|
|
"challenges/is-palindrome/solutions/c/function/input.c",
|
2022-04-23 18:41:14 +02:00
|
|
|
]
|
|
|
|
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(solutions, [
|
2022-04-23 18:41:14 +02:00
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "hello-world" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "javascript",
|
2022-04-23 18:41:14 +02:00
|
|
|
}),
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "is-palindrome" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "c",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
])
|
|
|
|
})
|
2021-12-07 12:11:54 +01:00
|
|
|
|
2022-04-23 18:41:14 +02:00
|
|
|
await t.test(
|
2023-10-23 23:16:24 +02:00
|
|
|
"returns the affected solutions from Dockerfile changes",
|
2023-07-20 22:00:11 +02:00
|
|
|
async () => {
|
2023-10-23 23:16:24 +02:00
|
|
|
const files = ["templates/docker/javascript/Dockerfile"]
|
2022-04-23 18:41:14 +02:00
|
|
|
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[0],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "camel-case" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "javascript",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[1],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "first-non-repeating-character" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "javascript",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-10-23 23:16:24 +02:00
|
|
|
},
|
2021-12-07 12:11:54 +01:00
|
|
|
)
|
|
|
|
|
2022-04-23 18:41:14 +02:00
|
|
|
await t.test(
|
2023-10-23 23:16:24 +02:00
|
|
|
"returns the affected solutions from Docker template changes",
|
2023-07-20 22:00:11 +02:00
|
|
|
async () => {
|
2023-10-23 23:16:24 +02:00
|
|
|
const files = ["templates/docker/javascript/package.json"]
|
2022-04-23 18:41:14 +02:00
|
|
|
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[0],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "camel-case" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "javascript",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[1],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "first-non-repeating-character" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "javascript",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-10-23 23:16:24 +02:00
|
|
|
},
|
2021-12-07 12:11:54 +01:00
|
|
|
)
|
|
|
|
|
2022-04-23 18:41:14 +02:00
|
|
|
await t.test(
|
2023-10-23 23:16:24 +02:00
|
|
|
"returns the affected solutions from input/output files",
|
2023-07-20 22:00:11 +02:00
|
|
|
async () => {
|
2023-10-23 23:16:24 +02:00
|
|
|
const files = ["challenges/hello-world/test/1/input.txt"]
|
2022-04-23 18:41:14 +02:00
|
|
|
const solutions = await gitAffected.getAffectedSolutionsFromFiles(files)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[0],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "hello-world" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "c",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[1],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "hello-world" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "cpp",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[2],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "hello-world" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "cs",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-07-20 22:00:11 +02:00
|
|
|
assert.deepStrictEqual(
|
2022-04-23 18:41:14 +02:00
|
|
|
solutions[3],
|
|
|
|
new Solution({
|
2023-10-23 23:16:24 +02:00
|
|
|
challenge: new Challenge({ name: "hello-world" }),
|
|
|
|
name: "function",
|
|
|
|
programmingLanguageName: "dart",
|
|
|
|
}),
|
2022-04-23 18:41:14 +02:00
|
|
|
)
|
2023-10-23 23:16:24 +02:00
|
|
|
},
|
2021-12-07 12:11:54 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|