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

Implementing Dinero JS into Invoice Form #116

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "node"
},
{
"name": "flask run",
"type": "python",
Expand Down
3 changes: 3 additions & 0 deletions static/checkout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
let stripe, clientSecret, elements, cardElement;
const DOMAIN = window.location.href;

import { lineItem, Quote } from "./quote.js";

window.addEventListener("DOMContentLoaded", () => {
getConfig().then(() => {
const appearance = {
Expand Down
60 changes: 60 additions & 0 deletions static/dinero.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { lineItem, Quote } = require("./quote");
const Dinero = require("dinero.js");
describe("lineItem", () => {
test("LineItem Test", () => {
const line_item = new lineItem({ price: 50, quantity: 1, salesTax: true });

expect(line_item).toBeDefined();
});
test("LineItem.details", () => {
const line_item = new lineItem({
price: 50,
quantity: 1,
salesTax: true,
});

expect(line_item.details).toEqual(
expect.objectContaining({
price: expect.any(Number),
quantity: expect.any(Number),
taxed: expect.any(Boolean),
})
);
});
});

describe("Quote", () => {
let lineItemArray = [];
let quote;
let dineroArray = [];
beforeEach(() => {
lineItemArray.push(
new lineItem({ price: 50.85, quantity: 2, salesTax: true })
);
lineItemArray.push(
new lineItem({ price: 50.85, quantity: 2, salesTax: true })
);
quote = new Quote(
lineItemArray,
(discount = { percentage: false, amount: 1.0 })
);
dineroArray = quote.dineroLineItems;
});
afterEach(() => {
lineItemArray.length = 0;
});

test("Create Quote", () => {
expect(quote).toBeDefined();
});
test("Quote.numberToDinero creates arrays of Dineros", () => {
expect(dineroArray.length).toEqual(lineItemArray.length);
});
test("dineroArray has an amount with cents", () => {
expect(dineroArray[0].getAmount()).toEqual(10170);
expect(dineroArray[0].hasCents()).toEqual(true);
});
test("quote has a subtotal dinero", () => {
expect(quote.dineroSubTotal.getAmount()).toEqual(10170 * 2);
});
});
Loading