|
| 1 | +import createQuoteRequestsSync, { actionGroups } from '../src/quote-requests' |
| 2 | +import { baseActionsList } from '../src/quote-requests-actions' |
| 3 | + |
| 4 | +describe('Exports', () => { |
| 5 | + test('action group list', () => { |
| 6 | + expect(actionGroups).toEqual(['base', 'custom']) |
| 7 | + }) |
| 8 | + |
| 9 | + describe('action list', () => { |
| 10 | + test('should contain `changeQuoteRequestState` action', () => { |
| 11 | + expect(baseActionsList).toEqual( |
| 12 | + expect.arrayContaining([{ action: 'changeQuoteRequestState', key: 'quoteRequestState' }]) |
| 13 | + ) |
| 14 | + }) |
| 15 | + |
| 16 | + test('should contain `transitionState` action', () => { |
| 17 | + expect(baseActionsList).toEqual( |
| 18 | + expect.arrayContaining([{ action: 'transitionState', key: 'state' }]) |
| 19 | + ) |
| 20 | + }) |
| 21 | + }) |
| 22 | +}) |
| 23 | + |
| 24 | +describe('Actions', () => { |
| 25 | + let quoteRequestsSync |
| 26 | + beforeEach(() => { |
| 27 | + quoteRequestsSync = createQuoteRequestsSync() |
| 28 | + }) |
| 29 | + |
| 30 | + test('should build `changeQuoteRequestState` action', () => { |
| 31 | + const before = { quoteRequestState: 'Submitted' } |
| 32 | + const now = { quoteRequestState: 'Accepted' } |
| 33 | + const actual = quoteRequestsSync.buildActions(now, before) |
| 34 | + const expected = [ |
| 35 | + { |
| 36 | + action: 'changeQuoteRequestState', |
| 37 | + ...now |
| 38 | + } |
| 39 | + ] |
| 40 | + expect(actual).toEqual(expected) |
| 41 | + }) |
| 42 | + |
| 43 | + test('should build `transitionState` action', () => { |
| 44 | + const before = { |
| 45 | + state : { |
| 46 | + typeId : 'state', |
| 47 | + id : 'sid1' |
| 48 | + } |
| 49 | + } |
| 50 | + const now = { |
| 51 | + state : { |
| 52 | + typeId : 'state', |
| 53 | + id : 'sid2' |
| 54 | + } |
| 55 | + } |
| 56 | + const actual = quoteRequestsSync.buildActions(now, before) |
| 57 | + const expected = [ |
| 58 | + { |
| 59 | + action: 'transitionState', |
| 60 | + ...now |
| 61 | + } |
| 62 | + ] |
| 63 | + expect(actual).toEqual(expected) |
| 64 | + }) |
| 65 | + |
| 66 | + test('should build `setCustomType` action', () => { |
| 67 | + const before = { |
| 68 | + custom: { |
| 69 | + type: { |
| 70 | + typeId: 'type', |
| 71 | + id: 'customType1', |
| 72 | + }, |
| 73 | + fields: { |
| 74 | + customField1: true, |
| 75 | + }, |
| 76 | + }, |
| 77 | + } |
| 78 | + const now = { |
| 79 | + custom: { |
| 80 | + type: { |
| 81 | + typeId: 'type', |
| 82 | + id: 'customType2', |
| 83 | + }, |
| 84 | + fields: { |
| 85 | + customField1: true, |
| 86 | + }, |
| 87 | + }, |
| 88 | + } |
| 89 | + const actual = quoteRequestsSync.buildActions(now, before) |
| 90 | + const expected = [{ action: 'setCustomType', ...now.custom }] |
| 91 | + expect(actual).toEqual(expected) |
| 92 | + }) |
| 93 | + |
| 94 | + test('should build `setCustomField` action', () => { |
| 95 | + const before = { |
| 96 | + custom: { |
| 97 | + type: { |
| 98 | + typeId: 'type', |
| 99 | + id: 'customType1', |
| 100 | + }, |
| 101 | + fields: { |
| 102 | + customField1: false, |
| 103 | + }, |
| 104 | + }, |
| 105 | + } |
| 106 | + const now = { |
| 107 | + custom: { |
| 108 | + type: { |
| 109 | + typeId: 'type', |
| 110 | + id: 'customType1', |
| 111 | + }, |
| 112 | + fields: { |
| 113 | + customField1: true, |
| 114 | + }, |
| 115 | + }, |
| 116 | + } |
| 117 | + const actual = quoteRequestsSync.buildActions(now, before) |
| 118 | + const expected = [ |
| 119 | + { |
| 120 | + action: 'setCustomField', |
| 121 | + name: 'customField1', |
| 122 | + value: true, |
| 123 | + }, |
| 124 | + ] |
| 125 | + expect(actual).toEqual(expected) |
| 126 | + }) |
| 127 | +}) |
0 commit comments