Changed:
- Env key to be more generic - Cache directory to .cache - Multiply bank amount by 100 to get correct conversion rate Removed: - Unused functions in Actual.ts Added: - Test for main functionality - BankStub for testing - Added imported_id to Actual Transaction to avoid duplicates
This commit is contained in:
12
tests/main.test.ts
Normal file
12
tests/main.test.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { describe, it } from "node:test"
|
||||
import { daily } from "@/main.ts"
|
||||
import { ActualImpl } from "@/actual.ts"
|
||||
import { BankStub } from "./stubs/bankStub.ts"
|
||||
import assert from "node:assert"
|
||||
|
||||
describe("Main logic of the application", () => {
|
||||
it("should import the transactions to Actual Budget", async () => {
|
||||
await daily(await ActualImpl.init(), new BankStub())
|
||||
assert.ok(true)
|
||||
})
|
||||
})
|
49
tests/stubs/bankStub.ts
Normal file
49
tests/stubs/bankStub.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import type { Bank, OAuthTokenResponse, Transaction } from "@/sparebank1.ts"
|
||||
|
||||
const tokenResponse: OAuthTokenResponse = {
|
||||
access_token: "my_access_token",
|
||||
token_type: "Bearer",
|
||||
expires_in: 3600,
|
||||
refresh_token: "my_refresh_token",
|
||||
refresh_token_expires_in: 3600,
|
||||
refresh_token_absolute_expires_in: 3600,
|
||||
}
|
||||
|
||||
export class BankStub implements Bank {
|
||||
async accessToken(): Promise<OAuthTokenResponse> {
|
||||
return tokenResponse
|
||||
}
|
||||
|
||||
async refreshToken(_unused: string): Promise<OAuthTokenResponse> {
|
||||
return tokenResponse
|
||||
}
|
||||
|
||||
async transactionsPastDay(
|
||||
_accountIds: ReadonlyArray<string> | string,
|
||||
_accessToken: string,
|
||||
): Promise<ReadonlyArray<Transaction>> {
|
||||
const someFields = {
|
||||
date: new Date().toDateString(),
|
||||
description: "Test transaction",
|
||||
cleanedDescription: "Test transaction",
|
||||
remoteAccountName: "Test account",
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: "1",
|
||||
amount: 100,
|
||||
...someFields,
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
amount: 200,
|
||||
...someFields,
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
amount: -50,
|
||||
...someFields,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user