Skip to content

Commit a5bca97

Browse files
committed
wip invoice line
1 parent 62e1fdf commit a5bca97

File tree

9 files changed

+81
-41
lines changed

9 files changed

+81
-41
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ __MACOSX
1010
.vscode
1111
.idea
1212
dist/
13+
.env

.mocharc.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ui": "bdd",
3+
"timeout": 30000,
4+
"extension": ["ts"],
5+
"spec": ["test/**/*.spec.ts"],
6+
"require": ["ts-node/register", "hooks.ts"],
7+
"package": "./package.json"
8+
}

lib/InvoiceLine.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export interface InvoiceLineInput {
1111
}
1212

1313
export enum InvoiceLineCategory {
14-
'services',
15-
'rent',
16-
'royalties',
17-
'royalties_film',
18-
'prizes',
19-
'education',
20-
'refunds',
14+
'services' = 'services',
15+
'rent' = 'rent',
16+
'royalties' = 'royalties',
17+
'royalties_film' = 'royalties_film',
18+
'prizes' = 'prizes',
19+
'education' = 'education',
20+
'refunds' = 'refunds',
2121
}
2222

2323
export class InvoiceLine {

package-lock.json

+18-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"@types/node": "~11.9.2",
3434
"@types/sinon": "~7.0.5",
3535
"@types/uuid": "~3.4.4",
36-
"mocha": "~5.2.0",
36+
"dotenv": "~16.0.3",
37+
"mocha": "~10.1.0",
3738
"nock": "~13.2.9",
3839
"sinon": "~7.2.3",
3940
"ts-node": "~8.0.2",

test/hooks.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
process.env.NODE_ENV = 'test';
2+
process.env.TS_NODE_PROJECT = 'src/tsconfig.json';
3+
4+
exports.mochaHooks = {
5+
beforeAll: () => {
6+
console.log('beforeAll');
7+
},
8+
};

test/integration/InvoiceLineSpec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { startNockRec } from "./helpers/integrationTestsHelpers";
2+
import { RecipientFactory } from "./factories/RecipientFactory";
3+
import { InvoiceFactory } from "./factories/InvoiceFactory";
4+
import { InvoiceLineFactory } from "./factories/InvoiceLineFactory";
5+
import * as assert from "assert";
6+
7+
let recipientFactory: RecipientFactory;
8+
let invoiceFactory: InvoiceFactory;
9+
let invoiceLineFactory: InvoiceLineFactory;
10+
11+
before(async () => {
12+
recipientFactory = new RecipientFactory();
13+
invoiceFactory = new InvoiceFactory();
14+
invoiceLineFactory = new InvoiceLineFactory();
15+
});
16+
17+
describe("InvoiceLine", () => {
18+
it("creates an invoice line", async () => {
19+
const nockDone = await startNockRec('invoice-line-create.json');
20+
21+
const recipient = await recipientFactory.createResource();
22+
const invoice = await invoiceFactory.createResource({ recipientId: recipient.id });
23+
const invoiceLine = await invoiceLineFactory.createResource({ invoice: { id: invoice.id } });
24+
25+
assert.ok(invoiceLine);
26+
assert.strictEqual("testInvoiceLine", invoiceLine.externalId);
27+
assert.strictEqual(invoice.id, invoiceLine.invoiceId);
28+
29+
nockDone();
30+
});
31+
});

test/integration/factories/InvoiceLineFactory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export class InvoiceLineFactory extends ApiFactory {
2020
public async createResource(attrs: any = {}) {
2121
return await this.apiClient.invoiceLine.create(
2222
attrs.invoice.id,
23-
{
23+
[{
2424
...InvoiceLineFactory.defaultAttrs,
2525
...attrs
26-
}
26+
}],
2727
);
2828
}
2929
}

test/tsconfig.json

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
11
{
2-
"include": [
3-
"../lib/**/*.ts"
2+
"extends": "../tsconfig.json",
3+
"require": [
4+
"ts-node/register",
5+
"hooks.ts"
46
],
5-
"exclude": [
6-
"node_modules",
7-
"dist",
8-
"spec"
9-
],
10-
"compilerOptions": {
11-
"target": "es6",
12-
"module": "commonjs",
13-
"lib": [
14-
"es7",
15-
"esnext.asynciterable",
16-
"es2015",
17-
"es2016",
18-
"es2017"
19-
],
20-
"declaration": true,
21-
"outDir": "dist",
22-
"rootDir": "..",
23-
"strict": true,
24-
"noImplicitAny": true,
25-
"moduleResolution": "node",
26-
"types": [
27-
"node",
28-
"mocha",
29-
"core-js"
30-
]
31-
}
327
}

0 commit comments

Comments
 (0)