1+ import createQuotesSync , { actionGroups } from '../src/quotes'
2+ import { baseActionsList } from '../src/quotes-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 `changeQuoteState` action' , ( ) => {
11+ expect ( baseActionsList ) . toEqual (
12+ expect . arrayContaining ( [ { action : 'changeQuoteState' , key : 'quoteState' } ] )
13+ )
14+ } )
15+
16+ test ( 'should contain `requestQuoteRenegotiation` action' , ( ) => {
17+ expect ( baseActionsList ) . toEqual (
18+ expect . arrayContaining ( [ { action : 'requestQuoteRenegotiation' , key : 'buyerComment' } ] )
19+ )
20+ } )
21+
22+ test ( 'should contain `transitionState` action' , ( ) => {
23+ expect ( baseActionsList ) . toEqual (
24+ expect . arrayContaining ( [ { action : 'transitionState' , key : 'state' } ] )
25+ )
26+ } )
27+ } )
28+ } )
29+
30+ describe ( 'Actions' , ( ) => {
31+ let quotesSync
32+ beforeEach ( ( ) => {
33+ quotesSync = createQuotesSync ( )
34+ } )
35+
36+ test ( 'should build `changeQuoteState` action' , ( ) => {
37+ const before = { quoteState : 'Pending' }
38+ const now = { quoteState : 'Approved' }
39+ const actual = quotesSync . buildActions ( now , before )
40+ const expected = [
41+ {
42+ action : 'changeQuoteState' ,
43+ ...now
44+ }
45+ ]
46+ expect ( actual ) . toEqual ( expected )
47+ } )
48+
49+ test ( 'should build `requestQuoteRenegotiation` action' , ( ) => {
50+ const before = { buyerComment : '' }
51+ const now = { buyerComment : 'give me a 10% discount' }
52+ const actual = quotesSync . buildActions ( now , before )
53+ const expected = [
54+ {
55+ action : 'requestQuoteRenegotiation' ,
56+ ...now
57+ }
58+ ]
59+ expect ( actual ) . toEqual ( expected )
60+ } )
61+
62+ test ( 'should build `transitionState` action' , ( ) => {
63+ const before = {
64+ state : {
65+ typeId : 'state' ,
66+ id : 'sid1'
67+ }
68+ }
69+ const now = {
70+ state : {
71+ typeId : 'state' ,
72+ id : 'sid2'
73+ }
74+ }
75+ const actual = quotesSync . buildActions ( now , before )
76+ const expected = [
77+ {
78+ action : 'transitionState' ,
79+ ...now
80+ }
81+ ]
82+ expect ( actual ) . toEqual ( expected )
83+ } )
84+
85+ test ( 'should build `setCustomType` action' , ( ) => {
86+ const before = {
87+ custom : {
88+ type : {
89+ typeId : 'type' ,
90+ id : 'customType1' ,
91+ } ,
92+ fields : {
93+ customField1 : true ,
94+ } ,
95+ } ,
96+ }
97+ const now = {
98+ custom : {
99+ type : {
100+ typeId : 'type' ,
101+ id : 'customType2' ,
102+ } ,
103+ fields : {
104+ customField1 : true ,
105+ } ,
106+ } ,
107+ }
108+ const actual = quotesSync . buildActions ( now , before )
109+ const expected = [ { action : 'setCustomType' , ...now . custom } ]
110+ expect ( actual ) . toEqual ( expected )
111+ } )
112+
113+ test ( 'should build `setCustomField` action' , ( ) => {
114+ const before = {
115+ custom : {
116+ type : {
117+ typeId : 'type' ,
118+ id : 'customType1' ,
119+ } ,
120+ fields : {
121+ customField1 : false ,
122+ } ,
123+ } ,
124+ }
125+ const now = {
126+ custom : {
127+ type : {
128+ typeId : 'type' ,
129+ id : 'customType1' ,
130+ } ,
131+ fields : {
132+ customField1 : true ,
133+ } ,
134+ } ,
135+ }
136+ const actual = quotesSync . buildActions ( now , before )
137+ const expected = [
138+ {
139+ action : 'setCustomField' ,
140+ name : 'customField1' ,
141+ value : true ,
142+ } ,
143+ ]
144+ expect ( actual ) . toEqual ( expected )
145+ } )
146+ } )
0 commit comments