-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
357 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
src | ||
rollup.config.js | ||
tsconfig.json | ||
import-sorter.json |
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,13 @@ | ||
module.exports = { | ||
coveragePathIgnorePatterns: ["/node_modules/", "/build/"], | ||
moduleFileExtensions: ["js", "jsx", "ts", "tsx"], | ||
moduleNameMapper: { | ||
"^@/(.*)$": "<rootDir>/src/$1", | ||
}, | ||
setupFiles: [], | ||
testMatch: ["**/*.test.ts", "**/*.test.tsx", "**/*.test.js"], | ||
testURL: "http://localhost/", | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
~ Monthly | ||
Expenses:Droga 15 EUR | ||
Assets:Banca | ||
|
||
2021-01-01 * Opening Balance | ||
Assets:Banca 1000 EUR | ||
Equity:Opening Balances | ||
|
||
2021-06-02 Nulla | ||
Assets:Banca 20 EUR | ||
Expenses:Droga -20 EUR | ||
|
||
2021-11-02 Nulla | ||
Assets:Banca 40 EUR | ||
Expenses:Droga -40 EUR | ||
|
||
|
||
2021-11-04 Pino | ||
34 EUR | ||
|
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 @@ | ||
import { Stream } from 'stream'; | ||
|
||
function mockStream(str: string) { | ||
const stream = new Stream.Readable(); | ||
|
||
stream._read = function () { | ||
this.push(str); | ||
this.push(null); | ||
}; | ||
|
||
return stream; | ||
} | ||
|
||
export default mockStream; |
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,4 +1,5 @@ | ||
import formatTransaction from './format-transaction'; | ||
import parse from './parse'; | ||
import { Transaction } from './types'; | ||
|
||
export { formatTransaction, Transaction }; | ||
export { formatTransaction, Transaction, parse }; |
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,112 @@ | ||
import { createReadStream } from 'fs'; | ||
|
||
import mockStream from './__mocks__/string-stream'; | ||
import parse, { parseEntryLine, parseHeaderLine } from './parse'; | ||
|
||
describe("parseHeaderLine", () => { | ||
it("Confirmed and description", () => { | ||
expect(parseHeaderLine("2021-11-02 * Description")).toEqual({ | ||
date: new Date("2021-11-02"), | ||
confirmed: true, | ||
description: "Description", | ||
}); | ||
}); | ||
|
||
it("Not confirmed", () => { | ||
expect(parseHeaderLine("2021-11-02 Foo")).toEqual({ | ||
date: new Date("2021-11-02"), | ||
confirmed: false, | ||
description: "Foo", | ||
}); | ||
}); | ||
|
||
it("No description", () => { | ||
expect(parseHeaderLine("2021-11-02")).toEqual({ | ||
date: new Date("2021-11-02"), | ||
confirmed: false, | ||
description: "", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("parseEntryLine", () => { | ||
test("Line with commodity", () => { | ||
expect(parseEntryLine("Assets:Crypto:Coinbase 1942.96 EUR")).toEqual({ | ||
account: "Assets:Crypto:Coinbase", | ||
amount: "1942.96", | ||
commodity: "EUR", | ||
}); | ||
}); | ||
test("Line with just account", () => { | ||
expect(parseEntryLine("Assets:Crypto:Coinbase")).toEqual({ | ||
account: "Assets:Crypto:Coinbase", | ||
amount: undefined, | ||
commodity: undefined, | ||
}); | ||
}); | ||
|
||
test("Line with just value", () => { | ||
expect(parseEntryLine("Assets:Bank 34.00")).toEqual({ | ||
account: "Assets:Bank", | ||
amount: "34.00", | ||
commodity: undefined, | ||
}); | ||
}); | ||
|
||
test("Line with conversion data", () => { | ||
expect(parseEntryLine("Assets:Crypto -8.00 LTC @ 173.41 EUR")).toEqual( | ||
{ | ||
account: "Assets:Crypto", | ||
amount: "-8.00", | ||
commodity: "LTC", | ||
conversion: { amount: "173.41", commodity: "EUR" }, | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe("parse", () => { | ||
test("it works with file streams", async () => { | ||
const readStream = createReadStream(`src/__mocks__/prova.journal`); | ||
|
||
const p = await parse(readStream); | ||
|
||
expect(p.length).toBe(4); | ||
}); | ||
|
||
test("it works with string streams", async () => { | ||
const stream = mockStream(` | ||
2021-11-02 * Some shopping | ||
Assets:Crypto:Coinbase -8.00 LTC @ 173.41 EUR | ||
Assets:Crypto:Coinbase 1382.42 EUR | ||
Expenses:Fees:Coinbase | ||
2021-11-02 | ||
Assets:Crypto:Coinbase -0.5 ETH @ 3899.56 EUR | ||
Assets:Crypto:Coinbase 1942.96 EUR | ||
Expenses:Fees:Coinbase | ||
`); | ||
|
||
const p = await parse(stream); | ||
|
||
expect(p.length).toBe(2); | ||
const [first] = p; | ||
|
||
expect(first.date).toStrictEqual(new Date("2021-11-02")); | ||
expect(first.confirmed).toBe(true); | ||
expect(first.description).toBe("Some shopping"); | ||
expect(first.entries.length).toBe(3); | ||
|
||
expect(first.entries[0]).toEqual({ | ||
account: "Assets:Crypto:Coinbase", | ||
amount: "-8.00", | ||
commodity: "LTC", | ||
conversion: { | ||
amount: "173.41", | ||
commodity: "EUR", | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.