-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e42736
commit 536f8f7
Showing
9 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+4.79 KB
service/.yarn/cache/@types-chance-npm-1.1.6-3dfdc6e3e5-f4366f1b31.zip
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./source-code" | ||
export * from "./s3" | ||
export * from "./plan" | ||
export * from "./run" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Plan} from "./plan" | ||
import {SourceCode} from "./source-code" | ||
|
||
export interface BaseRun { | ||
readonly id: string | ||
readonly state: | ||
| "pending_validation" | ||
| "pending_approval" | ||
| "approved" | ||
| "rejected" | ||
createdAt: Date | ||
updatedAt: Date | ||
} | ||
|
||
export interface Run extends BaseRun { | ||
readonly sourceCode: SourceCode | ||
readonly plan: Plan | ||
} | ||
|
||
export function isRunApproved(run: BaseRun): boolean { | ||
return run.state === "approved" | ||
} | ||
|
||
export function isRunInProgress(run: BaseRun): boolean { | ||
return run.state !== "approved" && run.state !== "rejected" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {BaseRun, isRunApproved, isRunInProgress} from "@libs/domain" | ||
import {generateMockRun} from "@libs/testing" | ||
|
||
describe("isRunApproved", () => { | ||
it("should return true if the run state is 'approved'", () => { | ||
// Given | ||
const run: BaseRun = generateMockRun({state: "approved"}) | ||
|
||
// When | ||
const result = isRunApproved(run) | ||
|
||
// Expect | ||
expect(result).toBe(true) | ||
}) | ||
|
||
it("should return false if the run state is not 'approved'", () => { | ||
// Given | ||
const run: BaseRun = generateMockRun({state: "pending_approval"}) | ||
|
||
// When | ||
const result = isRunApproved(run) | ||
|
||
// Expect | ||
expect(result).toBe(false) | ||
}) | ||
}) | ||
|
||
describe("isRunInProgress", () => { | ||
it("should return true if the run state is not 'approved' or 'rejected'", () => { | ||
// Given | ||
const run: BaseRun = generateMockRun({state: "pending_approval"}) | ||
|
||
// When | ||
const result = isRunInProgress(run) | ||
|
||
// Expect | ||
expect(result).toBe(true) | ||
}) | ||
|
||
it("should return false if the run state is 'approved'", () => { | ||
// Given | ||
const run: BaseRun = generateMockRun({state: "approved"}) | ||
|
||
// When | ||
const result = isRunInProgress(run) | ||
|
||
// Expect | ||
expect(result).toBe(false) | ||
}) | ||
|
||
it("should return false if the run state is 'rejected'", () => { | ||
// Given | ||
const run: BaseRun = generateMockRun({state: "rejected"}) | ||
|
||
// When | ||
const result = isRunInProgress(run) | ||
|
||
// Expect | ||
expect(result).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./mocks/run" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {BaseRun} from "@libs/domain" | ||
// eslint-disable-next-line node/no-unpublished-import | ||
import {Chance} from "chance" | ||
|
||
const random = new Chance() | ||
|
||
export function generateMockRun(overrides: Partial<BaseRun>): BaseRun { | ||
const baseObj: BaseRun = { | ||
id: random.guid(), | ||
state: random.pickone([ | ||
"pending_validation", | ||
"pending_approval", | ||
"approved", | ||
"rejected" | ||
]), | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
...overrides | ||
} | ||
|
||
return { | ||
...baseObj, | ||
...overrides | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters