|
| 1 | +import test from 'tape'; |
| 2 | +import { closeTestFyo, getTestFyo, setupTestFyo } from 'tests/helpers'; |
| 3 | +import { ItemEnquiry } from 'models/baseModels/ItemEnquiry/ItemEnquiry'; |
| 4 | +import { ModelNameEnum } from 'models/types'; |
| 5 | + |
| 6 | +const fyo = getTestFyo(); |
| 7 | +setupTestFyo(fyo, __filename); |
| 8 | + |
| 9 | +test('ItemEnquiry lifecycle with similarProduct', async (t) => { |
| 10 | + const initialData = { |
| 11 | + item: 'Test Pen', |
| 12 | + customer: 'CustomerOne', |
| 13 | + contact: '1234567890', |
| 14 | + description: 'Need details about bulk purchase', |
| 15 | + similarProduct: 'Ink', |
| 16 | + }; |
| 17 | + |
| 18 | + try { |
| 19 | + const newEnquiry = fyo.doc.getNewDoc( |
| 20 | + ModelNameEnum.ItemEnquiry, |
| 21 | + initialData |
| 22 | + ) as ItemEnquiry; |
| 23 | + await newEnquiry.sync(); |
| 24 | + |
| 25 | + const createdEnquiry = (await fyo.doc.getDoc( |
| 26 | + ModelNameEnum.ItemEnquiry, |
| 27 | + newEnquiry.name as string |
| 28 | + )) as ItemEnquiry; |
| 29 | + |
| 30 | + t.ok(createdEnquiry, 'ItemEnquiry was created and fetched from DB'); |
| 31 | + t.equal(createdEnquiry.item, initialData.item, 'Item matches after save'); |
| 32 | + t.equal( |
| 33 | + createdEnquiry.similarProduct, |
| 34 | + initialData.similarProduct, |
| 35 | + 'Similar product saved correctly' |
| 36 | + ); |
| 37 | + |
| 38 | + const updatedData = { |
| 39 | + description: 'Updated enquiry details', |
| 40 | + similarProduct: 'Gel Pen', |
| 41 | + }; |
| 42 | + |
| 43 | + createdEnquiry.description = updatedData.description; |
| 44 | + createdEnquiry.similarProduct = updatedData.similarProduct; |
| 45 | + await createdEnquiry.sync(); |
| 46 | + |
| 47 | + const updatedEnquiry = (await fyo.doc.getDoc( |
| 48 | + ModelNameEnum.ItemEnquiry, |
| 49 | + newEnquiry.name as string |
| 50 | + )) as ItemEnquiry; |
| 51 | + |
| 52 | + t.equal( |
| 53 | + updatedEnquiry.description, |
| 54 | + updatedData.description, |
| 55 | + 'Description updated successfully' |
| 56 | + ); |
| 57 | + t.equal( |
| 58 | + updatedEnquiry.similarProduct, |
| 59 | + updatedData.similarProduct, |
| 60 | + 'Similar product updated successfully' |
| 61 | + ); |
| 62 | + } catch (err) { |
| 63 | + t.fail(err as string); |
| 64 | + } |
| 65 | +}); |
| 66 | + |
| 67 | +closeTestFyo(fyo, __filename); |
0 commit comments