Skip to content

Commit 1e541ac

Browse files
refactor: clean code, add more test scripts (#34)
* add integration tests to scripts * refactor: rename to FactorialAuthenticator, remove dead code * refactor: remove not needed toPrimitives * refactor: simplify workflows * refactor: update dependencies without grouping and daily * refactor: add auto merge bot * only run ci if targeting main * refactor: extract project variable to env * chore: bump version
1 parent bebf038 commit 1e541ac

18 files changed

+97
-111
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
FACTORIAL_USER_EMAIL=[email protected]
22
FACTORIAL_USER_PASSWORD=yourpassword
3+
FACTORIAL_PROJECT_NAME=yourprojectname

.github/dependabot.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@ updates:
33
- package-ecosystem: "github-actions"
44
directory: "/"
55
schedule:
6-
interval: "weekly"
7-
time: "09:00"
8-
timezone: "Europe/Madrid"
6+
interval: "daily"
97
- package-ecosystem: "npm"
108
directory: "/"
11-
groups:
12-
dependencies:
13-
dependency-type: production
14-
dev-dependencies:
15-
dependency-type: development
169
schedule:
17-
interval: "weekly"
18-
time: "09:00"
19-
timezone: "Europe/Madrid"
10+
interval: "daily"

.github/workflows/ci.yml

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
48

59
jobs:
610
build:
711
runs-on: ubuntu-latest
812
steps:
9-
- name: Checkout repository
10-
uses: actions/checkout@v4
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
1115
with:
12-
fetch-depth: 2
13-
14-
- name: Set up Node.js
15-
uses: actions/setup-node@v4
16-
with:
17-
node-version: 20
18-
19-
- name: Install dependencies
20-
run: npm install
21-
22-
- name: Check types
23-
run: npm run typecheck
24-
25-
- name: Run the tests
26-
run: npm run test
27-
28-
- name: Build
29-
run: npm run build
16+
node-version: 22
17+
- run: npm ci
18+
- run: npm run typecheck
19+
- run: npm run test
20+
- run: npm run build

.github/workflows/dependabot.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: auto-merge
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
auto-merge:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: ahmadnassri/action-dependabot-auto-merge@v2
12+
with:
13+
target: major
14+
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

.github/workflows/npm-publish.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ jobs:
1515
- uses: actions/setup-node@v4
1616
with:
1717
node-version: 20
18-
- name: Install dependencies
19-
run: npm ci
20-
- name: Build
21-
run: npm run build
22-
- name: Test
23-
run: npm test
18+
- run: npm ci
19+
- run: npm run build
20+
- run: npm test
2421

2522
publish-npm:
2623
needs: build
@@ -31,11 +28,8 @@ jobs:
3128
with:
3229
node-version: 20
3330
registry-url: https://registry.npmjs.org
34-
- name: Install dependencies
35-
run: npm ci
36-
- name: Build
37-
run: npm run build
38-
- name: Publish
39-
run: npm publish
31+
- run: npm ci
32+
- run: npm run build
33+
- run: npm publish
4034
env:
4135
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ build
66

77
node_modules
88
dist
9+
coverage

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "factorial-cli",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"type": "module",
55
"description": "Fill your factorial shifts with ease",
66
"main": "dist/src/infrastructure/cli/main.js",
@@ -12,6 +12,8 @@
1212
"scripts": {
1313
"test": "npm run test:unitary",
1414
"test:unitary": "vitest --config vite.config.unitary.ts",
15+
"test:integration": "vitest --config vite.config.integration.ts",
16+
"test:e2e": "vitest --config vite.config.e2e.ts",
1517
"build": "tsc",
1618
"clean": "rimraf dist coverage",
1719
"typecheck": "tsc --noEmit"

src/domain/models/Day.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { Primitives } from "../../shared/Primitives.js";
2-
import { Leave } from "./Leave.js";
1+
import { Leave, LeavePrimitives } from "./Leave.js";
32
import { PeriodId } from "./PeriodId.js";
43
import { Shift } from "./Shift.js";
54
import { DayRange } from "./DayRange.js";
65
import { DayNumber } from "./DayNumber.js";
76
import { MonthOfTheYear } from "./MonthOfTheYear.js";
87
import { EmployeeId } from "./EmployeeId.js";
98

10-
export type DayPrimitives = Primitives<Day>;
9+
export type DayPrimitives = {
10+
dayNumber: number;
11+
leaves: Array<LeavePrimitives>;
12+
isLaborable: boolean;
13+
};
1114

1215
export class Day {
1316
static fromPrimitives(primitives: DayPrimitives) {
@@ -18,10 +21,6 @@ export class Day {
1821
);
1922
}
2023

21-
static toPrimitives(day: Day) {
22-
return day.toPrimitives();
23-
}
24-
2524
static at(number: number) {
2625
return new Day(new DayNumber(number), [], true);
2726
}
@@ -56,14 +55,6 @@ export class Day {
5655
);
5756
}
5857

59-
toPrimitives() {
60-
return {
61-
dayNumber: this.dayNumber.toPrimitives(),
62-
leaves: this.leaves.map(Leave.toPrimitives),
63-
isLaborable: this.isLaborable,
64-
};
65-
}
66-
6758
toString(): string {
6859
return this.dayNumber.toString();
6960
}

src/domain/models/Leave.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
import { Primitives } from "../../shared/Primitives.js";
2-
3-
export type LeavePrimitives = Primitives<Leave>;
1+
export type LeavePrimitives = {
2+
name: string;
3+
};
44

55
export class Leave {
66
static fromPrimitives(primitives: LeavePrimitives) {
77
return new Leave(primitives.name);
88
}
99

10-
static toPrimitives(leave: Leave) {
11-
return leave.toPrimitives();
12-
}
13-
1410
constructor(private readonly name: string) {}
15-
16-
toPrimitives() {
17-
return {
18-
name: this.name,
19-
};
20-
}
2111
}

src/domain/models/Month.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Day } from "./Day.js";
2-
import { Primitives } from "../../shared/Primitives.js";
3-
import { MonthOfTheYear } from "./MonthOfTheYear.js";
1+
import { Day, DayPrimitives } from "./Day.js";
2+
import { MonthOfTheYear, MonthOfTheYearPrimitives } from "./MonthOfTheYear.js";
43

5-
type MonthPrimitives = Primitives<Month>;
4+
type MonthPrimitives = {
5+
monthOfTheYear: MonthOfTheYearPrimitives;
6+
days: Array<DayPrimitives>;
7+
};
68

79
export class Month {
810
static fromPrimitives(primitives: MonthPrimitives) {
@@ -20,11 +22,4 @@ export class Month {
2022
daysBefore(date: Date) {
2123
return this.days.filter((day) => day.toDate(this.monthOfTheYear) < date);
2224
}
23-
24-
toPrimitives() {
25-
return {
26-
monthOfTheYear: this.monthOfTheYear.toPrimitives(),
27-
days: this.days.map(Day.toPrimitives),
28-
};
29-
}
3025
}

0 commit comments

Comments
 (0)