vend 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/README.rdoc +8 -0
- data/Rakefile +18 -0
- data/example.rb +51 -0
- data/lib/vend.rb +24 -0
- data/lib/vend/base.rb +200 -0
- data/lib/vend/base_factory.rb +34 -0
- data/lib/vend/client.rb +82 -0
- data/lib/vend/exception.rb +35 -0
- data/lib/vend/http_client.rb +119 -0
- data/lib/vend/logable.rb +9 -0
- data/lib/vend/null_logger.rb +9 -0
- data/lib/vend/pagination_info.rb +30 -0
- data/lib/vend/resource/customer.rb +11 -0
- data/lib/vend/resource/outlet.rb +7 -0
- data/lib/vend/resource/payment_type.rb +7 -0
- data/lib/vend/resource/product.rb +12 -0
- data/lib/vend/resource/register.rb +7 -0
- data/lib/vend/resource/register_sale.rb +19 -0
- data/lib/vend/resource/register_sale_product.rb +21 -0
- data/lib/vend/resource/tax.rb +7 -0
- data/lib/vend/resource/user.rb +7 -0
- data/lib/vend/resource_collection.rb +132 -0
- data/lib/vend/scope.rb +27 -0
- data/lib/vend/version.rb +3 -0
- data/spec/integration/customer_spec.rb +33 -0
- data/spec/integration/outlet_spec.rb +15 -0
- data/spec/integration/payment_types_spec.rb +15 -0
- data/spec/integration/product_spec.rb +76 -0
- data/spec/integration/register_sale_spec.rb +35 -0
- data/spec/integration/register_spec.rb +16 -0
- data/spec/integration/tax_spec.rb +16 -0
- data/spec/integration/user_spec.rb +16 -0
- data/spec/mock_responses/customers.find_by_email.json +44 -0
- data/spec/mock_responses/customers.json +20 -0
- data/spec/mock_responses/outlets.json +14 -0
- data/spec/mock_responses/payment_types.json +7 -0
- data/spec/mock_responses/products.active.since.json +184 -0
- data/spec/mock_responses/products.json +115 -0
- data/spec/mock_responses/products/page/1.json +130 -0
- data/spec/mock_responses/products/page/2.json +130 -0
- data/spec/mock_responses/register_sales.find_by_state.json +324 -0
- data/spec/mock_responses/register_sales.json +158 -0
- data/spec/mock_responses/register_sales/2e658bce-9627-bc27-d77d-6c9ba2e8216e.json +158 -0
- data/spec/mock_responses/registers.json +32 -0
- data/spec/mock_responses/taxes.json +7 -0
- data/spec/mock_responses/users.json +17 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/matchers/have_attributes.rb +11 -0
- data/spec/support/shared_examples/integration.rb +79 -0
- data/spec/support/shared_examples/logger.rb +25 -0
- data/spec/vend/base_factory_spec.rb +48 -0
- data/spec/vend/base_spec.rb +348 -0
- data/spec/vend/client_spec.rb +93 -0
- data/spec/vend/http_client_spec.rb +129 -0
- data/spec/vend/null_logger_spec.rb +5 -0
- data/spec/vend/pagination_info_spec.rb +48 -0
- data/spec/vend/resource/register_sale_product_spec.rb +27 -0
- data/spec/vend/resource/register_sale_spec.rb +24 -0
- data/spec/vend/resource_collection_spec.rb +312 -0
- data/spec/vend/scope_spec.rb +41 -0
- data/vend.gemspec +26 -0
- metadata +179 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
{
|
2
|
+
"register_sales" : [ { "id": "98ce3dbf-e862-c811-fa93-10f6db3a8f66",
|
3
|
+
"register_id": "6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
4
|
+
"market_id": "1",
|
5
|
+
"customer_id": "6cbfbc20-3d5f-11e0-8697-4040f540b50a",
|
6
|
+
"customer_name": "",
|
7
|
+
"customer": {
|
8
|
+
"id": "6cbfbc20-3d5f-11e0-8697-4040f540b50a",
|
9
|
+
"name": "",
|
10
|
+
"customer_code": "WALKIN",
|
11
|
+
"customer_group_id": "6cbee822-3d5f-11e0-8697-4040f540b50a",
|
12
|
+
"customer_group_name": "All Customers",
|
13
|
+
"updated_at": "2012-02-15 23:34:15",
|
14
|
+
"deleted_at": "",
|
15
|
+
"balance": "0.000",
|
16
|
+
"year_to_date": "23.85000",
|
17
|
+
"points": "0",
|
18
|
+
"custom_field_1": "",
|
19
|
+
"custom_field_2": "",
|
20
|
+
"custom_field_3": "",
|
21
|
+
"custom_field_4": "",
|
22
|
+
"contact": {
|
23
|
+
}
|
24
|
+
},
|
25
|
+
"user_id": "85b7853a-52cd-11e1-8cd4-4040dde94e2e",
|
26
|
+
"user_name": "greg.signal@trineo.co.nz",
|
27
|
+
"sale_date": "2012-02-15 23:33:57",
|
28
|
+
"created_at": "2012-02-15 23:34:15",
|
29
|
+
"updated_at": "2012-02-15 23:34:15",
|
30
|
+
"total_price": 20.73,
|
31
|
+
"total_tax": 3.12,
|
32
|
+
"tax_name": "NZ GST",
|
33
|
+
"note": "",
|
34
|
+
"status": "CLOSED",
|
35
|
+
"short_code": "80smy",
|
36
|
+
"invoice_number": "2",
|
37
|
+
"register_sale_products": [ {
|
38
|
+
"id" :"80730b76-94ef-7677-50b3-0802ad448819",
|
39
|
+
"product_id" :"6cd62cbc-3d5f-11e0-8697-4040f540b50a",
|
40
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
41
|
+
"sequence" :"0",
|
42
|
+
"handle" :"coffee",
|
43
|
+
"sku" :"coffee-hot",
|
44
|
+
"name" :"Coffee (Demo)",
|
45
|
+
"quantity" : 1,
|
46
|
+
"price" : 2.61,
|
47
|
+
"price_set" : 0,
|
48
|
+
"tax" : 0.39,
|
49
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
50
|
+
"tax_rate" : 0.15,
|
51
|
+
"tax_total" : 0.39,
|
52
|
+
"price_total" : 2.61,
|
53
|
+
"display_retail_price_tax_inclusive" : "1",
|
54
|
+
"status" : "CONFIRMED"
|
55
|
+
}, {
|
56
|
+
"id" :"e3b1fbd7-6942-00b4-776b-77374277eda3",
|
57
|
+
"product_id" :"6cd62cbc-3d5f-11e0-8697-4040f540b50a",
|
58
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
59
|
+
"sequence" :"0",
|
60
|
+
"handle" :"coffee",
|
61
|
+
"sku" :"coffee-hot",
|
62
|
+
"name" :"Coffee (Demo)",
|
63
|
+
"quantity" : 1,
|
64
|
+
"price" : 2.61,
|
65
|
+
"price_set" : 0,
|
66
|
+
"tax" : 0.39,
|
67
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
68
|
+
"tax_rate" : 0.15,
|
69
|
+
"tax_total" : 0.39,
|
70
|
+
"price_total" : 2.61,
|
71
|
+
"display_retail_price_tax_inclusive" : "1",
|
72
|
+
"status" : "CONFIRMED"
|
73
|
+
}, {
|
74
|
+
"id" :"251ee7b5-5ac7-1a18-a467-7527a5b54406",
|
75
|
+
"product_id" :"6cc53042-3d5f-11e0-8697-4040f540b50a",
|
76
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
77
|
+
"sequence" :"1",
|
78
|
+
"handle" :"tshirt",
|
79
|
+
"sku" :"tshirt-white",
|
80
|
+
"name" :"T-shirt (Demo)",
|
81
|
+
"quantity" : 1,
|
82
|
+
"price" : 4.3,
|
83
|
+
"price_set" : 0,
|
84
|
+
"tax" : 0.65,
|
85
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
86
|
+
"tax_rate" : 0.15,
|
87
|
+
"tax_total" : 0.65,
|
88
|
+
"price_total" : 4.3,
|
89
|
+
"display_retail_price_tax_inclusive" : "1",
|
90
|
+
"status" : "CONFIRMED"
|
91
|
+
}, {
|
92
|
+
"id" :"17199ec2-db5a-dec5-c483-015fbb92a5a5",
|
93
|
+
"product_id" :"6cc53042-3d5f-11e0-8697-4040f540b50a",
|
94
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
95
|
+
"sequence" :"2",
|
96
|
+
"handle" :"tshirt",
|
97
|
+
"sku" :"tshirt-white",
|
98
|
+
"name" :"T-shirt (Demo)",
|
99
|
+
"quantity" : 1,
|
100
|
+
"price" : 4.3,
|
101
|
+
"price_set" : 0,
|
102
|
+
"tax" : 0.65,
|
103
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
104
|
+
"tax_rate" : 0.15,
|
105
|
+
"tax_total" : 0.65,
|
106
|
+
"price_total" : 4.3,
|
107
|
+
"display_retail_price_tax_inclusive" : "1",
|
108
|
+
"status" : "CONFIRMED"
|
109
|
+
}, {
|
110
|
+
"id" :"40feb90b-dffb-957c-0227-f552cefb2370",
|
111
|
+
"product_id" :"6cc53042-3d5f-11e0-8697-4040f540b50a",
|
112
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
113
|
+
"sequence" :"3",
|
114
|
+
"handle" :"tshirt",
|
115
|
+
"sku" :"tshirt-white",
|
116
|
+
"name" :"T-shirt (Demo)",
|
117
|
+
"quantity" : 1,
|
118
|
+
"price" : 4.3,
|
119
|
+
"price_set" : 0,
|
120
|
+
"tax" : 0.65,
|
121
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
122
|
+
"tax_rate" : 0.15,
|
123
|
+
"tax_total" : 0.65,
|
124
|
+
"price_total" : 4.3,
|
125
|
+
"display_retail_price_tax_inclusive" : "1",
|
126
|
+
"status" : "CONFIRMED"
|
127
|
+
}, {
|
128
|
+
"id" :"81a03160-eac3-eb97-f43a-a4c1297ad330",
|
129
|
+
"product_id" :"6cd62cbc-3d5f-11e0-8697-4040f540b50a",
|
130
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
131
|
+
"sequence" :"4",
|
132
|
+
"handle" :"coffee",
|
133
|
+
"sku" :"coffee-hot",
|
134
|
+
"name" :"Coffee (Demo)",
|
135
|
+
"quantity" : 1,
|
136
|
+
"price" : 2.61,
|
137
|
+
"price_set" : 0,
|
138
|
+
"tax" : 0.39,
|
139
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
140
|
+
"tax_rate" : 0.15,
|
141
|
+
"tax_total" : 0.39,
|
142
|
+
"price_total" : 2.61,
|
143
|
+
"display_retail_price_tax_inclusive" : "1",
|
144
|
+
"status" : "CONFIRMED"
|
145
|
+
} ],
|
146
|
+
"totals": { "total_tax" : 3.12,
|
147
|
+
"total_price" : 20.73,
|
148
|
+
"total_payment" : 23.85,
|
149
|
+
"total_to_pay" : 0 },
|
150
|
+
"register_sale_payments" : [ {"id" : "23d8f36f-500c-ac6f-cd68-465ae4ed96e1",
|
151
|
+
"payment_type_id" : "1",
|
152
|
+
"register_id" : "",
|
153
|
+
"retailer_payment_type_id" : "6cde3ba0-3d5f-11e0-8697-4040f540b50a",
|
154
|
+
"name" : "Cash",
|
155
|
+
"payment_date" : "2012-02-15 23:33:56",
|
156
|
+
"amount" : 23.85} ]
|
157
|
+
} ]
|
158
|
+
}
|
@@ -0,0 +1,158 @@
|
|
1
|
+
{
|
2
|
+
"register_sales" : [ { "id": "98ce3dbf-e862-c811-fa93-10f6db3a8f66",
|
3
|
+
"register_id": "6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
4
|
+
"market_id": "1",
|
5
|
+
"customer_id": "6cbfbc20-3d5f-11e0-8697-4040f540b50a",
|
6
|
+
"customer_name": "",
|
7
|
+
"customer": {
|
8
|
+
"id": "6cbfbc20-3d5f-11e0-8697-4040f540b50a",
|
9
|
+
"name": "",
|
10
|
+
"customer_code": "WALKIN",
|
11
|
+
"customer_group_id": "6cbee822-3d5f-11e0-8697-4040f540b50a",
|
12
|
+
"customer_group_name": "All Customers",
|
13
|
+
"updated_at": "2012-02-24 00:25:56",
|
14
|
+
"deleted_at": "",
|
15
|
+
"balance": "0.000",
|
16
|
+
"year_to_date": "41.70000",
|
17
|
+
"points": "0",
|
18
|
+
"custom_field_1": "",
|
19
|
+
"custom_field_2": "",
|
20
|
+
"custom_field_3": "",
|
21
|
+
"custom_field_4": "",
|
22
|
+
"contact": {
|
23
|
+
}
|
24
|
+
},
|
25
|
+
"user_id": "85b7853a-52cd-11e1-8cd4-4040dde94e2e",
|
26
|
+
"user_name": "greg.signal@trineo.co.nz",
|
27
|
+
"sale_date": "2012-02-15 23:33:57",
|
28
|
+
"created_at": "2012-02-15 23:34:15",
|
29
|
+
"updated_at": "2012-02-15 23:34:15",
|
30
|
+
"total_price": 20.73,
|
31
|
+
"total_tax": 3.12,
|
32
|
+
"tax_name": "NZ GST",
|
33
|
+
"note": "",
|
34
|
+
"status": "CLOSED",
|
35
|
+
"short_code": "80smy",
|
36
|
+
"invoice_number": "2",
|
37
|
+
"register_sale_products": [ {
|
38
|
+
"id" :"80730b76-94ef-7677-50b3-0802ad448819",
|
39
|
+
"product_id" :"6cd62cbc-3d5f-11e0-8697-4040f540b50a",
|
40
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
41
|
+
"sequence" :"0",
|
42
|
+
"handle" :"coffee",
|
43
|
+
"sku" :"coffee-hot",
|
44
|
+
"name" :"Coffee (Demo)",
|
45
|
+
"quantity" : 1,
|
46
|
+
"price" : 2.61,
|
47
|
+
"price_set" : 0,
|
48
|
+
"tax" : 0.39,
|
49
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
50
|
+
"tax_rate" : 0.15,
|
51
|
+
"tax_total" : 0.39,
|
52
|
+
"price_total" : 2.61,
|
53
|
+
"display_retail_price_tax_inclusive" : "1",
|
54
|
+
"status" : "CONFIRMED"
|
55
|
+
}, {
|
56
|
+
"id" :"e3b1fbd7-6942-00b4-776b-77374277eda3",
|
57
|
+
"product_id" :"6cd62cbc-3d5f-11e0-8697-4040f540b50a",
|
58
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
59
|
+
"sequence" :"0",
|
60
|
+
"handle" :"coffee",
|
61
|
+
"sku" :"coffee-hot",
|
62
|
+
"name" :"Coffee (Demo)",
|
63
|
+
"quantity" : 1,
|
64
|
+
"price" : 2.61,
|
65
|
+
"price_set" : 0,
|
66
|
+
"tax" : 0.39,
|
67
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
68
|
+
"tax_rate" : 0.15,
|
69
|
+
"tax_total" : 0.39,
|
70
|
+
"price_total" : 2.61,
|
71
|
+
"display_retail_price_tax_inclusive" : "1",
|
72
|
+
"status" : "CONFIRMED"
|
73
|
+
}, {
|
74
|
+
"id" :"251ee7b5-5ac7-1a18-a467-7527a5b54406",
|
75
|
+
"product_id" :"6cc53042-3d5f-11e0-8697-4040f540b50a",
|
76
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
77
|
+
"sequence" :"1",
|
78
|
+
"handle" :"tshirt",
|
79
|
+
"sku" :"tshirt-white",
|
80
|
+
"name" :"T-shirt (Demo)",
|
81
|
+
"quantity" : 1,
|
82
|
+
"price" : 4.3,
|
83
|
+
"price_set" : 0,
|
84
|
+
"tax" : 0.65,
|
85
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
86
|
+
"tax_rate" : 0.15,
|
87
|
+
"tax_total" : 0.65,
|
88
|
+
"price_total" : 4.3,
|
89
|
+
"display_retail_price_tax_inclusive" : "1",
|
90
|
+
"status" : "CONFIRMED"
|
91
|
+
}, {
|
92
|
+
"id" :"17199ec2-db5a-dec5-c483-015fbb92a5a5",
|
93
|
+
"product_id" :"6cc53042-3d5f-11e0-8697-4040f540b50a",
|
94
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
95
|
+
"sequence" :"2",
|
96
|
+
"handle" :"tshirt",
|
97
|
+
"sku" :"tshirt-white",
|
98
|
+
"name" :"T-shirt (Demo)",
|
99
|
+
"quantity" : 1,
|
100
|
+
"price" : 4.3,
|
101
|
+
"price_set" : 0,
|
102
|
+
"tax" : 0.65,
|
103
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
104
|
+
"tax_rate" : 0.15,
|
105
|
+
"tax_total" : 0.65,
|
106
|
+
"price_total" : 4.3,
|
107
|
+
"display_retail_price_tax_inclusive" : "1",
|
108
|
+
"status" : "CONFIRMED"
|
109
|
+
}, {
|
110
|
+
"id" :"40feb90b-dffb-957c-0227-f552cefb2370",
|
111
|
+
"product_id" :"6cc53042-3d5f-11e0-8697-4040f540b50a",
|
112
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
113
|
+
"sequence" :"3",
|
114
|
+
"handle" :"tshirt",
|
115
|
+
"sku" :"tshirt-white",
|
116
|
+
"name" :"T-shirt (Demo)",
|
117
|
+
"quantity" : 1,
|
118
|
+
"price" : 4.3,
|
119
|
+
"price_set" : 0,
|
120
|
+
"tax" : 0.65,
|
121
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
122
|
+
"tax_rate" : 0.15,
|
123
|
+
"tax_total" : 0.65,
|
124
|
+
"price_total" : 4.3,
|
125
|
+
"display_retail_price_tax_inclusive" : "1",
|
126
|
+
"status" : "CONFIRMED"
|
127
|
+
}, {
|
128
|
+
"id" :"81a03160-eac3-eb97-f43a-a4c1297ad330",
|
129
|
+
"product_id" :"6cd62cbc-3d5f-11e0-8697-4040f540b50a",
|
130
|
+
"register_id" :"6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
131
|
+
"sequence" :"4",
|
132
|
+
"handle" :"coffee",
|
133
|
+
"sku" :"coffee-hot",
|
134
|
+
"name" :"Coffee (Demo)",
|
135
|
+
"quantity" : 1,
|
136
|
+
"price" : 2.61,
|
137
|
+
"price_set" : 0,
|
138
|
+
"tax" : 0.39,
|
139
|
+
"tax_id" : "53b3501c-887c-102d-8a4b-a9cf13f17faa",
|
140
|
+
"tax_rate" : 0.15,
|
141
|
+
"tax_total" : 0.39,
|
142
|
+
"price_total" : 2.61,
|
143
|
+
"display_retail_price_tax_inclusive" : "1",
|
144
|
+
"status" : "CONFIRMED"
|
145
|
+
} ],
|
146
|
+
"totals": { "total_tax" : 3.12,
|
147
|
+
"total_price" : 20.73,
|
148
|
+
"total_payment" : 23.85,
|
149
|
+
"total_to_pay" : 0 },
|
150
|
+
"register_sale_payments" : [ {"id" : "23d8f36f-500c-ac6f-cd68-465ae4ed96e1",
|
151
|
+
"payment_type_id" : "1",
|
152
|
+
"register_id" : "",
|
153
|
+
"retailer_payment_type_id" : "6cde3ba0-3d5f-11e0-8697-4040f540b50a",
|
154
|
+
"name" : "Cash",
|
155
|
+
"payment_date" : "2012-02-15 23:33:56",
|
156
|
+
"amount" : 23.85} ]
|
157
|
+
} ]
|
158
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"registers" : [ {
|
3
|
+
"id": "6cbe2342-3d5f-11e0-8697-4040f540b50a",
|
4
|
+
"name": "Main Register",
|
5
|
+
"outlet_id": "6cb5c88c-3d5f-11e0-8697-4040f540b50a",
|
6
|
+
"print_receipt" : "1",
|
7
|
+
"email_receipt" : "0",
|
8
|
+
"ask_for_note_on_save" : "1",
|
9
|
+
"print_note_on_receipt" : "0",
|
10
|
+
"ask_for_user_on_sale" : "0",
|
11
|
+
"receipt_header": "<h1>Trineo Dev Account<h1>",
|
12
|
+
"receipt_footer": "<h1>Thanks for stopping by<h1>",
|
13
|
+
"receipt_style_sheet": "\/css\/receipt\/receipt_80.css?v=2.30.03",
|
14
|
+
"invoice_prefix": "",
|
15
|
+
"invoice_suffix": "",
|
16
|
+
"invoice_sequence": 1,
|
17
|
+
"register_open_count_sequence": "2",
|
18
|
+
"register_open_time": "2012-02-08 06:22:36",
|
19
|
+
"register_close_time": "",
|
20
|
+
"quick_keys": [ { "page_label" : "",
|
21
|
+
"keys" : [
|
22
|
+
{
|
23
|
+
"position" : "1",
|
24
|
+
"label" : "T-shirt (Demo)",
|
25
|
+
"sku" : "tshirt-white"}, {
|
26
|
+
"position" : "2",
|
27
|
+
"label" : "Coffee (Demo)",
|
28
|
+
"sku" : "coffee-hot"} ]
|
29
|
+
}
|
30
|
+
],
|
31
|
+
"quick_keys_template": {"quick_keys":{"groups":[{"name":"Default","position":0,"pages":[{"page":1,"keys":[{"position":0,"label":"T-shirt (Demo)","sku":"tshirt-white","product_id":"6cc53042-3d5f-11e0-8697-4040f540b50a","color":"white","parent":false},{"position":1,"label":"Coffee (Demo)","sku":"coffee-hot","product_id":"6cd62cbc-3d5f-11e0-8697-4040f540b50a","color":"white","parent":false}]}]}]}} } ]
|
32
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"users" : [ {
|
3
|
+
"id": "6ce4286c-3d5f-11e0-8697-4040f540b50a",
|
4
|
+
"username": "user@example.com",
|
5
|
+
"name": "A cashier",
|
6
|
+
"outlet_id": "",
|
7
|
+
"outlet_name": "",
|
8
|
+
"account_type": "admin"
|
9
|
+
}, {
|
10
|
+
"id": "85b7853a-52cd-11e1-8cd4-4040dde94e2e",
|
11
|
+
"username": "greg.signal@trineo.co.nz",
|
12
|
+
"name": "A cashier",
|
13
|
+
"outlet_id": "6cb5c88c-3d5f-11e0-8697-4040f540b50a",
|
14
|
+
"outlet_name": "Main Outlet",
|
15
|
+
"account_type": "admin"
|
16
|
+
} ]
|
17
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
Dir["./spec/support/**/*.rb"].each {|f| require f}
|
6
|
+
|
7
|
+
require 'cgi'
|
8
|
+
require 'vend'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_mock_response(file)
|
15
|
+
File.read(File.join(File.dirname(__FILE__), 'mock_responses/', file))
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
RSpec::Matchers.define :have_attributes do |expected|
|
2
|
+
match do |attributes|
|
3
|
+
expected.each do |key,value|
|
4
|
+
actual.send(key).should == value
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
failure_message_for_should do |actual|
|
9
|
+
"expected #{actual.attrs} to match #{expected}"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
def url(store, username, password)
|
2
|
+
"https://#{username}:#{password}@#{store}.vendhq.com/api/"
|
3
|
+
end
|
4
|
+
|
5
|
+
def get_mock_from_path(method, options = {})
|
6
|
+
file_path = described_class.endpoint_name.pluralize
|
7
|
+
file_path += "/#{options[:id]}" if options[:id]
|
8
|
+
file_path = file_path + '.' + method.to_s unless method == :get
|
9
|
+
get_mock_response("#{file_path}.json")
|
10
|
+
end
|
11
|
+
|
12
|
+
def class_basename
|
13
|
+
described_class.name.split('::').last
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_receiver
|
17
|
+
client.send(class_basename)
|
18
|
+
end
|
19
|
+
|
20
|
+
shared_examples "a resource with a collection GET endpoint" do
|
21
|
+
|
22
|
+
let(:username) {"foo"}
|
23
|
+
let(:password) {"bar"}
|
24
|
+
let(:store) {"baz"}
|
25
|
+
|
26
|
+
let(:client) do
|
27
|
+
Vend::Client.new(store, username, password)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets the collection" do
|
31
|
+
stub_request(:get, "https://#{username}:#{password}@#{store}.vendhq.com/api/#{class_basename.to_s.underscore.pluralize}").
|
32
|
+
to_return(:status => 200, :body => get_mock_from_path(:get))
|
33
|
+
|
34
|
+
collection = build_receiver.all
|
35
|
+
collection.count.should == expected_collection_length
|
36
|
+
|
37
|
+
first = collection.first
|
38
|
+
first.should have_attributes(expected_attributes)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
shared_examples "a resource with a singular GET endpoint" do
|
43
|
+
|
44
|
+
let(:username) {"foo"}
|
45
|
+
let(:password) {"bar"}
|
46
|
+
let(:store) {"baz"}
|
47
|
+
|
48
|
+
let(:client) do
|
49
|
+
Vend::Client.new(store, username, password)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "gets the resource" do
|
53
|
+
stub_request(:get, "https://#{username}:#{password}@#{store}.vendhq.com/api/#{class_basename.to_s.underscore.pluralize}/#{id}").
|
54
|
+
to_return(:status => 200, :body => get_mock_from_path(:get, :id => id))
|
55
|
+
|
56
|
+
objekt = build_receiver.find(id)
|
57
|
+
objekt.should have_attributes(expected_attributes)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
shared_examples "a resource with a DELETE endpoint" do
|
62
|
+
|
63
|
+
let(:username) {"foo"}
|
64
|
+
let(:password) {"bar"}
|
65
|
+
let(:store) {"baz"}
|
66
|
+
|
67
|
+
let(:client) do
|
68
|
+
Vend::Client.new(store, username, password)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "deletes the resource" do
|
72
|
+
stub_request(:delete, "https://#{username}:#{password}@#{store}.vendhq.com/api/#{class_basename.to_s.underscore.pluralize}/#{expected_attributes['id']}").
|
73
|
+
to_return(:status => 200, :body => {})
|
74
|
+
|
75
|
+
objekt = build_receiver.build(expected_attributes)
|
76
|
+
objekt.delete.should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|