-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
239 lines (203 loc) · 6.67 KB
/
command_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package gongoff
import (
"fmt"
"testing"
"time"
)
// TestCommandProduct tests the creation of a CommandProduct command.
func TestCommandProduct(t *testing.T) {
productName := "BREAD"
quantity := 2
department := 3
commandProduct := NewCommandProduct(750, &productName, &quantity, &department)
command, err := commandProduct.get()
if err != nil {
panic(err)
}
if command != "\"BREAD\"2*750H3R" {
t.Errorf("Expected \"BREAD\"2*750H3R, got %s", command)
}
commandProductDefaults := NewCommandProduct(750, nil, nil, nil)
commandDefaults, err := commandProductDefaults.get()
if err != nil {
panic(err)
}
if commandDefaults != "750H1R" {
t.Errorf("Expected 750H1R, got %s", commandDefaults)
}
fmt.Println("Completed testCommandProduct")
}
// TestCommandTrailer tests the creation of a CommandMessage command.
func TestCommandTrailer(t *testing.T) {
commandMessage := NewCommandTrailer("Hello World!")
command, err := commandMessage.get()
if err != nil {
panic(err)
}
if command != "\"Hello World! \"@40F" {
t.Errorf("Expected \"Hello World! \"@40F, got %s", command)
}
commandMessageLong := NewCommandTrailer("Hello World! truncate this")
command, err = commandMessageLong.get()
if err != nil {
panic(err)
}
if command != "\"Hello World! trunc\"@40F" {
t.Errorf("Expected \"Hello World! trunc\"@40F, got %s", command)
}
fmt.Println("Completed testCommandMessage")
}
// TestCommandPayment tests the creation of a CommandPayment command.
func TestCommandPayment(t *testing.T) {
testDesc := "test"
testAmount := 100
commandPayment, err := NewCommandPayment(TerminatorTypePaymentCards, &testAmount, &testDesc)
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
command, err := commandPayment.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "100H\"test\"3T" {
t.Errorf("Expected 100H\"test\"3T, got %s", command)
}
_, err = NewCommandPayment(TerminatorTypeSold, nil, nil)
if err == nil {
t.Errorf("Expected error != nil, got nil")
}
fmt.Println("Completed testCommandPayment")
}
func TestCommandCustomerIdentifier(t *testing.T) {
commandCustomerIdentifier, err := NewCommandCustomerIdentifier("RSSMRA00A01F205F")
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
command, err := commandCustomerIdentifier.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "\"RSSMRA00A01F205F\"@39F" {
t.Errorf("Expected \"RSSMRA00A01F205F\"@39F, got %s", command)
}
_, err = NewCommandCustomerIdentifier("test")
if err == nil {
t.Errorf("Expected error != nil, got nil")
}
fmt.Println("Completed testNewCommandCustomerIdentifier")
}
func TestCommandDiscountPercentage(t *testing.T) {
commandDiscountPercentage := NewCommandDiscountPercentage(50.12)
command, err := commandDiscountPercentage.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "50.121M" {
t.Errorf("Expected 50.121M, got %s", command)
}
fmt.Println("Completed testCommandDiscountPercentage")
}
func TestCommandDiscountAmount(t *testing.T) {
commandDiscountAmount := NewCommandDiscountAmount(1126)
command, err := commandDiscountAmount.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "1126H3M" {
t.Errorf("Expected 1126H3M, got %s", command)
}
fmt.Println("Completed testCommandDiscountAmount")
}
func TestCommandBarcode(t *testing.T) {
commandBarcode, err := NewCommandBarcode("1234567890123")
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
command, err := commandBarcode.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "\"1234567890123\"1Z" {
t.Errorf("Expected \"1234567890123\"1Z, got %s", command)
}
_, err = NewCommandBarcode("test")
if err == nil {
t.Errorf("Expected error != nil, got nil")
}
fmt.Println("Completed testCommandBarcode")
}
func TestCommandOpenDocumentCommercialReturn(t *testing.T) {
testDate := time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)
documentId := NewDocumentId(12, 23, testDate, nil)
commandOpenDocumentCommercialReturn := NewCommandOpenDocumentCommercialReturn(*documentId)
command, err := commandOpenDocumentCommercialReturn.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "\"0012-0023-01-01-18\"104M" {
t.Errorf("Expected \"0012-0023-01-01-18\"104M, got %s", command)
}
fmt.Println("Completed testCommandOpenDocumentCommercialReturn")
}
func TestCommandOpenInvoice(t *testing.T) {
invNum := 123
commandOpenInvoice := NewCommandOpenInvoice(&invNum)
command, err := commandOpenInvoice.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "\"00123\"101M" {
t.Errorf("Expected \"00123\"101M, got %s", command)
}
commandOpenInvoiceZero := NewCommandOpenInvoice(nil)
commandZero, err := commandOpenInvoiceZero.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if commandZero != "\"00000\"101M" {
t.Errorf("Expected \"00000\"101M, got %s", command)
}
fmt.Println("Completed testCommandOpenInvoice")
}
func TestCommandOpenInvoiceCommercialDocument(t *testing.T) {
invNum := 123
commandOpenInvoice := NewCommandOpenInvoiceCommercialDocument(&invNum)
command, err := commandOpenInvoice.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "\"00123\"111M" {
t.Errorf("Expected \"00123\"111M, got %s", command)
}
commandOpenInvoiceZero := NewCommandOpenInvoiceCommercialDocument(nil)
commandZero, err := commandOpenInvoiceZero.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if commandZero != "\"00000\"111M" {
t.Errorf("Expected \"00000\"111M, got %s", command)
}
fmt.Println("Completed testCommandOpenInvoice")
}
func TestCommandInvoiceDetails(t *testing.T) {
commandInvoiceDetails := NewCommandInvoiceDetails("Mario Rossi")
command, err := commandInvoiceDetails.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "\"Mario Rossi \"@38F" {
t.Errorf("Expected \"Mario Rossi \"@38F, got %s", command)
}
fmt.Println("Completed testCommandInvoiceDetails")
}
func TestCommandDisplayMessage(t *testing.T) {
commandDisplayMessage := NewCommandDisplayMessage("Mario Rossi", 1)
command, err := commandDisplayMessage.get()
if err != nil {
t.Errorf("Expected error = nil, got %s", err)
}
if command != "\"Mario Rossi\"1%" {
t.Errorf("Expected \"Mario Rossi\"1%%, got %s", command)
}
fmt.Println("Completed testCommandDisplayMessage")
}