2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 19:39:07 +00:00
books/models/baseModels/tests/testLead.spec.ts

122 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-08-09 05:11:54 +00:00
import test from 'tape';
import { closeTestFyo, getTestFyo, setupTestFyo } from 'tests/helpers';
import { ModelNameEnum } from 'models/types';
import { Lead } from '../Lead/Lead';
import { Party } from '../Party/Party';
const fyo = getTestFyo();
setupTestFyo(fyo, __filename);
const leadData = {
name: 'name2',
status: 'Open',
email: 'sample@gmail.com',
2024-08-12 05:20:05 +00:00
mobile: '1234567890',
2024-08-09 05:11:54 +00:00
};
const itemData: { name: string; rate: number } = {
name: 'Pen',
rate: 100,
};
test('create test docs for Lead', async (t) => {
await fyo.doc.getNewDoc(ModelNameEnum.Item, itemData).sync();
t.ok(
fyo.db.exists(ModelNameEnum.Item, itemData.name),
`dummy item ${itemData.name} exists`
);
});
test('create a Lead doc', async (t) => {
await fyo.doc.getNewDoc(ModelNameEnum.Lead, leadData).sync();
t.ok(
fyo.db.exists(ModelNameEnum.Lead, leadData.name),
`${leadData.name} exists`
);
});
test('create Customer from Lead', async (t) => {
const leadDoc = (await fyo.doc.getDoc(ModelNameEnum.Lead, 'name2')) as Lead;
2024-08-09 10:26:10 +00:00
const newCustomer = leadDoc.createCustomer();
2024-08-09 05:11:54 +00:00
t.equals(
leadDoc.status,
'Open',
2024-08-09 10:26:10 +00:00
'status must be Open before Customer is created'
2024-08-09 05:11:54 +00:00
);
2024-08-09 10:26:10 +00:00
await newCustomer.sync();
2024-08-09 05:11:54 +00:00
t.equals(
leadDoc.status,
'Converted',
2024-08-09 10:26:10 +00:00
'status should change to Converted after Customer is created'
2024-08-09 05:11:54 +00:00
);
t.ok(
2024-08-09 10:26:10 +00:00
await fyo.db.exists(ModelNameEnum.Party, newCustomer.name),
2024-08-09 05:11:54 +00:00
'Customer created from Lead'
);
});
test('create SalesQuote', async (t) => {
const leadDoc = (await fyo.doc.getDoc(ModelNameEnum.Lead, 'name2')) as Lead;
2024-08-09 10:26:10 +00:00
const newSalesQuote = leadDoc.createSalesQuote();
newSalesQuote.items = [];
newSalesQuote.append('items', {
item: itemData.name,
quantity: 1,
rate: itemData.rate,
});
2024-08-09 05:11:54 +00:00
t.equals(
leadDoc.status,
'Converted',
'status must be Open before SQUOT is created'
);
2024-08-09 10:26:10 +00:00
await newSalesQuote.sync();
await newSalesQuote.submit();
2024-08-09 05:11:54 +00:00
t.equals(
leadDoc.status,
'Quotation',
'status should change to Quotation after SQUOT submission'
);
t.ok(
2024-08-09 10:26:10 +00:00
await fyo.db.exists(ModelNameEnum.SalesQuote, newSalesQuote.name),
2024-08-09 05:11:54 +00:00
'SalesQuote Created from Lead'
);
});
test('delete Customer then lead status changes to Interested', async (t) => {
const partyDoc = (await fyo.doc.getDoc(
ModelNameEnum.Party,
'name2'
)) as Party;
2024-08-09 10:26:10 +00:00
2024-08-09 05:11:54 +00:00
await partyDoc.delete();
t.equals(
await fyo.db.exists(ModelNameEnum.Party, 'name2'),
false,
'Customer deleted'
);
2024-08-09 10:26:10 +00:00
2024-08-09 05:11:54 +00:00
const leadDoc = (await fyo.doc.getDoc(ModelNameEnum.Lead, 'name2')) as Lead;
t.equals(
leadDoc.status,
'Interested',
2024-08-09 10:26:10 +00:00
'status should change to Interested after Customer is deleted'
2024-08-09 05:11:54 +00:00
);
});
closeTestFyo(fyo, __filename);