-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added additional test cases and set test file system base url to test…
…-files
- Loading branch information
Showing
11 changed files
with
398 additions
and
40 deletions.
There are no files selected for viewing
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,11 +1,15 @@ | ||
import { assert } from '@japa/assert' | ||
import { configure, processCLIArgs, run } from '@japa/runner' | ||
import { fileSystem } from '@japa/file-system' | ||
|
||
processCLIArgs(process.argv.splice(2)) | ||
|
||
configure({ | ||
files: ['tests/**/*.spec.ts'], | ||
plugins: [assert()], | ||
plugins: [ | ||
assert(), | ||
fileSystem({ basePath: new URL('../test-files', import.meta.url), autoClean: false }), | ||
], | ||
}) | ||
|
||
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
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,100 @@ | ||
// @ts-nocheck | ||
import { DateTime } from 'luxon' | ||
import { BaseModel, belongsTo, column, computed, hasMany, hasOne } from '@adonisjs/lucid/orm' | ||
import User from './user.js' | ||
import type { BelongsTo, HasMany, HasOne } from '@adonisjs/lucid/types/relations' | ||
import AccountType from '#models/account_type' | ||
import Payee from '#models/payee' | ||
import Stock from '#models/stock' | ||
import Transaction from '#models/transaction' | ||
import AccountTypeService from '#services/account_type_service' | ||
import { columnCurrency } from '#start/orm/column' | ||
import type { AccountGroupConfig } from '#config/account' | ||
|
||
export default class Account extends BaseModel { | ||
// region Columns | ||
|
||
@column({ isPrimary: true }) | ||
declare id: number | ||
|
||
@column() | ||
declare userId: number | ||
|
||
@column() | ||
declare accountTypeId: number | ||
|
||
@column() | ||
declare name: string | ||
|
||
@column() | ||
declare note: string | ||
|
||
@column.date() | ||
declare dateOpened: DateTime | null | ||
|
||
@column.date() | ||
declare dateClosed: DateTime | null | ||
|
||
@columnCurrency() | ||
declare balance: number | ||
|
||
@columnCurrency() | ||
declare startingBalance: number | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
declare createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
declare updatedAt: DateTime | ||
|
||
// endregion | ||
|
||
// region Unmapped Properties | ||
|
||
aggregations: Record<string, number> = {} | ||
|
||
// endregion | ||
|
||
// region Relationships | ||
|
||
@belongsTo(() => User) | ||
declare user: BelongsTo<typeof User> | ||
|
||
@belongsTo(() => AccountType) | ||
declare accountType: BelongsTo<typeof AccountType> | ||
|
||
@hasOne(() => Payee) | ||
declare payee: HasOne<typeof Payee> | ||
|
||
@hasMany(() => Stock) | ||
declare stocks: HasMany<typeof Stock> | ||
|
||
@hasMany(() => Transaction) | ||
declare transactions: HasMany<typeof Transaction> | ||
|
||
// endregion | ||
|
||
// region Computed Properties | ||
|
||
@computed() | ||
get accountGroup(): AccountGroupConfig { | ||
return AccountTypeService.getAccountTypeGroup(this.accountTypeId) | ||
} | ||
|
||
@computed() | ||
get isCreditIncrease(): boolean { | ||
return AccountTypeService.isCreditIncreaseById(this.accountTypeId) | ||
} | ||
|
||
@computed() | ||
get isBudgetable() { | ||
return AccountTypeService.isBudgetable(this.accountTypeId) | ||
} | ||
|
||
@computed() | ||
get balanceDisplay() { | ||
return '$' + this.balance.toLocaleString('en-US') | ||
} | ||
|
||
// endregion | ||
} |
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,14 @@ | ||
// @ts-nocheck | ||
import { DateTime } from 'luxon' | ||
import { BaseModel, column } from '@adonisjs/lucid/orm' | ||
|
||
export default class Test extends BaseModel { | ||
@column({ isPrimary: true }) | ||
declare id: number | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
declare createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
declare updatedAt: DateTime | ||
} |
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,56 @@ | ||
// @ts-nocheck | ||
import { DateTime } from 'luxon' | ||
import hash from '@adonisjs/core/services/hash' | ||
import { compose } from '@adonisjs/core/helpers' | ||
import { BaseModel, column, hasMany } from '@adonisjs/lucid/orm' | ||
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid' | ||
import Payee from '#models/payee' | ||
import type { HasMany } from '@adonisjs/lucid/types/relations' | ||
import Transaction from '#models/transaction' | ||
import Income from '#models/income' | ||
import StockPurchase from '#models/stock_purchase' | ||
import Stock from '#models/stock' | ||
import Account from '#models/account' | ||
|
||
const AuthFinder = withAuthFinder(() => hash.use('scrypt'), { | ||
uids: ['email'], | ||
passwordColumnName: 'password', | ||
}) | ||
|
||
export default class User extends compose(BaseModel, AuthFinder) { | ||
@column({ isPrimary: true }) | ||
declare id: number | ||
|
||
@column() | ||
declare fullName: string | null | ||
|
||
@column() | ||
declare email: string | ||
|
||
@column({ serializeAs: null }) | ||
declare password: string | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
declare createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
declare updatedAt: DateTime | null | ||
|
||
@hasMany(() => Payee) | ||
declare payees: HasMany<typeof Payee> | ||
|
||
@hasMany(() => Transaction) | ||
declare transactions: HasMany<typeof Transaction> | ||
|
||
@hasMany(() => Income) | ||
declare incomes: HasMany<typeof Income> | ||
|
||
@hasMany(() => StockPurchase) | ||
declare stockPurchases: HasMany<typeof StockPurchase> | ||
|
||
@hasMany(() => Stock) | ||
declare stocks: HasMany<typeof Stock> | ||
|
||
@hasMany(() => Account) | ||
declare accounts: HasMany<typeof Account> | ||
} |
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,60 @@ | ||
import Account from '#models/account' | ||
import UserDto from '#dtos/user' | ||
import AccountTypeDto from '#dtos/account_type' | ||
import PayeeDto from '#dtos/payee' | ||
import StockDto from '#dtos/stock' | ||
import TransactionDto from '#dtos/transaction' | ||
import { AccountGroupConfig } from '#config/account' | ||
|
||
export default class AccountDto { | ||
declare id: number | ||
declare userId: number | ||
declare accountTypeId: number | ||
declare name: string | ||
declare note: string | ||
declare dateOpened: string | null | ||
declare dateClosed: string | null | ||
declare balance: number | ||
declare startingBalance: number | ||
declare createdAt: string | ||
declare updatedAt: string | ||
aggregations: Record<string, number> = {} | ||
declare user: UserDto | null | ||
declare accountType: AccountTypeDto | null | ||
declare payee: PayeeDto | null | ||
declare stocks: StockDto[] | ||
declare transactions: TransactionDto[] | ||
declare accountGroup: AccountGroupConfig | ||
declare isCreditIncrease: boolean | ||
declare isBudgetable: boolean | ||
declare balanceDisplay: string | ||
|
||
constructor(account: Account) { | ||
this.id = account.id | ||
this.userId = account.userId | ||
this.accountTypeId = account.accountTypeId | ||
this.name = account.name | ||
this.note = account.note | ||
this.dateOpened = account.dateOpened?.toISO()! | ||
this.dateClosed = account.dateClosed?.toISO()! | ||
this.balance = account.balance | ||
this.startingBalance = account.startingBalance | ||
this.createdAt = account.createdAt.toISO()! | ||
this.updatedAt = account.updatedAt.toISO()! | ||
this.aggregations = account.aggregations | ||
this.user = account.user && new UserDto(account.user) | ||
this.accountType = account.accountType && new AccountTypeDto(account.accountType) | ||
this.payee = account.payee && new PayeeDto(account.payee) | ||
this.stocks = StockDto.fromArray(account.stocks) | ||
this.transactions = TransactionDto.fromArray(account.transactions) | ||
this.accountGroup = account.accountGroup | ||
this.isCreditIncrease = account.isCreditIncrease | ||
this.isBudgetable = account.isBudgetable | ||
this.balanceDisplay = account.balanceDisplay | ||
} | ||
|
||
static fromArray(accounts: Account[]) { | ||
if (!accounts) return [] | ||
return accounts.map((account) => new AccountDto(account)) | ||
} | ||
} |
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,16 @@ | ||
import Test from '#models/test' | ||
|
||
export default class SomeTestDto { | ||
declare id: number | ||
declare createdAt: string | ||
|
||
constructor(test: Test) { | ||
this.id = test.id | ||
this.createdAt = test.createdAt.toISO()! | ||
} | ||
|
||
static fromArray(tests: Test[]) { | ||
if (!tests) return [] | ||
return tests.map((test) => new SomeTestDto(test)) | ||
} | ||
} |
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,16 @@ | ||
import Test from '#models/test' | ||
|
||
export default class TestDto { | ||
declare id: number | ||
declare createdAt: string | ||
|
||
constructor(test: Test) { | ||
this.id = test.id | ||
this.createdAt = test.createdAt.toISO()! | ||
} | ||
|
||
static fromArray(tests: Test[]) { | ||
if (!tests) return [] | ||
return tests.map((test) => new TestDto(test)) | ||
} | ||
} |
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,39 @@ | ||
import User from '#models/user' | ||
import PayeeDto from '#dtos/payee' | ||
import TransactionDto from '#dtos/transaction' | ||
import IncomeDto from '#dtos/income' | ||
import StockPurchaseDto from '#dtos/stock_purchase' | ||
import StockDto from '#dtos/stock' | ||
|
||
export default class UserDto { | ||
declare id: number | ||
declare fullName: string | null | ||
declare email: string | ||
declare password: string | ||
declare createdAt: string | ||
declare updatedAt: string | null | ||
declare payees: PayeeDto[] | ||
declare transactions: TransactionDto[] | ||
declare incomes: IncomeDto[] | ||
declare stockPurchases: StockPurchaseDto[] | ||
declare stocks: StockDto[] | ||
|
||
constructor(user: User) { | ||
this.id = user.id | ||
this.fullName = user.fullName | ||
this.email = user.email | ||
this.password = user.password | ||
this.createdAt = user.createdAt.toISO()! | ||
this.updatedAt = user.updatedAt?.toISO()! | ||
this.payees = PayeeDto.fromArray(user.payees) | ||
this.transactions = TransactionDto.fromArray(user.transactions) | ||
this.incomes = IncomeDto.fromArray(user.incomes) | ||
this.stockPurchases = StockPurchaseDto.fromArray(user.stockPurchases) | ||
this.stocks = StockDto.fromArray(user.stocks) | ||
} | ||
|
||
static fromArray(users: User[]) { | ||
if (!users) return [] | ||
return users.map((user) => new UserDto(user)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.