Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to hefty v2 #321

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions _templates/service/new/factory.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import <%= h.changeCase.pascal(name) %> from '../../src/entities/<%= name %>'

export default class <%= h.changeCase.pascal(name) %>Factory extends Factory<<%= h.changeCase.pascal(name) %>> {
constructor() {
super(<%= h.changeCase.pascal(name) %>, 'base')
this.register('base', this.base)
super(<%= h.changeCase.pascal(name) %>)
}

protected base(): Partial<<%= h.changeCase.pascal(name) %>> {
return {

}
protected definition(): void {
this.state(() => ({
// TODO
}))
}
}
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"watch": "tsx watch src/index.ts",
"build": "npx tsc -p tsconfig.build.json",
"dc": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml",
"dc": "docker compose -f docker-compose.yml -f docker-compose.dev.yml",
"seed": "DB_HOST=127.0.0.1 tsx tests/seed.ts",
"test": "./tests/run-tests.sh",
"up": "npm run dc -- up --build -d",
Expand Down Expand Up @@ -35,7 +35,7 @@
"@vitest/coverage-v8": "^1.5.2",
"axios-mock-adapter": "^1.22.0",
"eslint": "^8.26.0",
"hefty": "^1.1.0",
"hefty": "^2.0.0",
"husky": "^9.0.11",
"hygen": "^6.2.11",
"lint-staged": ">=10",
Expand Down
8 changes: 4 additions & 4 deletions tests/entities/player-group-rule/casting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('PlayerGroupRule casting', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('PlayerGroupRule casting', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('PlayerGroupRule casting', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'firstLoginAt', '2022-05-03 00:00:00')
])
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('PlayerGroupRule casting', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'firstLoginAt', '2022-05-03 08:59:36')
])
Expand Down
8 changes: 4 additions & 4 deletions tests/entities/player-group-rule/equals-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('EQUALS rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

Expand All @@ -38,7 +38,7 @@ describe('EQUALS rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

Expand All @@ -65,7 +65,7 @@ describe('EQUALS rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('EQUALS rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
Expand Down
16 changes: 8 additions & 8 deletions tests/entities/player-group-rule/gt-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('GT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -38,8 +38,8 @@ describe('GT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -65,12 +65,12 @@ describe('GT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '70')
])
Expand Down Expand Up @@ -100,12 +100,12 @@ describe('GT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '70')
])
Expand Down
16 changes: 8 additions & 8 deletions tests/entities/player-group-rule/gte-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('GTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -38,8 +38,8 @@ describe('GTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -65,12 +65,12 @@ describe('GTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '70')
])
Expand Down Expand Up @@ -100,12 +100,12 @@ describe('GTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '69')
])
Expand Down
16 changes: 8 additions & 8 deletions tests/entities/player-group-rule/lt-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('LT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -38,8 +38,8 @@ describe('LT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -65,12 +65,12 @@ describe('LT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '69')
])
Expand Down Expand Up @@ -100,12 +100,12 @@ describe('LT rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '70')
])
Expand Down
16 changes: 8 additions & 8 deletions tests/entities/player-group-rule/lte-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('LTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 1, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -38,8 +38,8 @@ describe('LTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).with(() => ({ lastSeenAt: new Date(2022, 6, 3) })).one()
const player1 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 4, 3) })).one()
const player2 = await new PlayerFactory([game]).state(() => ({ lastSeenAt: new Date(2022, 6, 3) })).one()
await (<EntityManager>global.em).persistAndFlush([player1, player2])

const rules: Partial<PlayerGroupRule>[] = [
Expand All @@ -65,12 +65,12 @@ describe('LTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '70')
])
Expand Down Expand Up @@ -100,12 +100,12 @@ describe('LTE rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '69')
])
Expand Down
4 changes: 2 additions & 2 deletions tests/entities/player-group-rule/set-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('SET rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'hasFinishedGame', '1')
])
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('SET rule', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'hasFinishedGame', '1')
])
Expand Down
6 changes: 3 additions & 3 deletions tests/entities/player-group/ruleMode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('PlayerGroupRule mode', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80'),
new PlayerProp(player, 'timePlayed', '23423')
Expand Down Expand Up @@ -50,13 +50,13 @@ describe('PlayerGroupRule mode', () => {
const [organisation, game] = await createOrganisationAndGame()
const [token] = await createUserAndToken({}, organisation)

const player1 = await new PlayerFactory([game]).with((player) => ({
const player1 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '80'),
new PlayerProp(player, 'timePlayed', '546565')
])
})).one()
const player2 = await new PlayerFactory([game]).with((player) => ({
const player2 = await new PlayerFactory([game]).state((player) => ({
props: new Collection<PlayerProp>(player, [
new PlayerProp(player, 'currentLevel', '29'),
new PlayerProp(player, 'timePlayed', '23423')
Expand Down
Loading