Skip to content

Commit

Permalink
Adds tests for Order features
Browse files Browse the repository at this point in the history
  - Created JSON fixtures for Order responses
  - Debugged camel case conversion error
  - Order.fields returns snake case fields
  • Loading branch information
allolex committed Jan 1, 2013
1 parent cee9489 commit 9efd14c
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/nacre/api/order_service_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def self.find_many(id_set)

def load_values(values)
self.class.fields.each do |field|
self.public_send "#{field.to_s.underscore}=", values[field.to_s].to_openstruct
self.public_send "#{field.to_s}=", values[field.to_s.camelize(:lower)].to_openstruct
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/nacre/api/order_service_resources/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Order < OrderServiceResource
]

def self.fields
FIELDS
FIELDS.map(&:to_s).map(&:underscore).map(&:to_sym)
end

fields.each do |attr|
Expand Down
33 changes: 14 additions & 19 deletions spec/api/order_service_resources/order_search_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,27 @@

it 'results items should be an array of OpenStructs' do
results.should be_a(Nacre::API::OrderSearchResults)
results.length.should == 7

results.items.first.orderId.should == 1000
results.items.first.orderName.should == "Misc item without VAT"
results.items.first.SKU.should == ""
results.items.first.EAN.should be_nil
results.items.first.UPC.should be_nil
results.items.first.ISBN.should be_nil
results.items.first.stockTracked.should == false
results.items.first.salesChannelName.should == "Brightpearl"
results.items.first.createdOn.should == "2007-05-29T10:42:08.000Z"
results.items.first.updatedOn.should == "2007-09-08T14:42:45.000Z"
results.items.first.brightpearlCategoryCode.should == 1000
results.items.first.orderGroupId.should == 0
results.length.should == 3

results.items.first.orderId.should == 123456
results.items.first.orderTypeId.should == 1
results.items.first.contactId.should == 253
results.items.first.orderStatusId.should == 4
results.items.first.orderStockStatusId.should == 3
results.items.first.createdOn.should == '2012-12-13T13:00:42.000Z'
results.items.first.createdById == '280'
end

it "should have the correct metadata" do
results.metadata.columns.length.should == 12
results.metadata.columns.length.should == 7
results.metadata.firstResult.should == 1
results.metadata.lastResult.should == 7
results.metadata.resultsAvailable.should == 7
results.metadata.resultsReturned.should == 7
results.metadata.lastResult.should == 3
results.metadata.resultsAvailable.should == 3
results.metadata.resultsReturned.should == 3
end

it "should return the id set of the search results" do
results.id_set.should =~ Array(1000..1006)
results.id_set.should =~ [123456,123457,123458]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/api/order_service_resources/order_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
response = mock("response")
response.stub(:body).and_return(response_json)
connection.should_receive(:get).
with(search_url).
with(search_url + '?pageSize=200&firstResult=1').
any_number_of_times.
and_return(response)
end
Expand Down
20 changes: 10 additions & 10 deletions spec/api/order_service_resources/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
response = mock("response")
response.stub(:body).and_return(response_json)
connection.should_receive(:get).
with("/order-service/order/1").
with("/order-service/order/123456").
any_number_of_times.
and_return(response)
end
Expand All @@ -61,7 +61,7 @@
let(:response_json) { { "response" => [] }.to_json }

it 'should return nil' do
Nacre::API::Order.find(1008).should be_nil
Nacre::API::Order.find(123456).should be_nil
end
end

Expand All @@ -70,11 +70,11 @@
let(:response_json) { IO.read("spec/fixtures/json/order.json") }

it 'should return a valid Order' do
order = Nacre::API::Order.find(1008)
order = Nacre::API::Order.find(123456)
order.should be_a(Nacre::API::Order)
order.id.should == 1008
order.identity["sku"].should == "SKU0001"
#order.orderTypeId.should == 1 #TODO uncamelize this
order.id.should == 123456
order.reference.should == 'order#001'
order.currency.accounting_currency_code.should == 'GBP'
end
end
end
Expand All @@ -101,7 +101,7 @@
response = mock("response")
response.stub(:body).and_return(response_json)
connection.should_receive(:get).
with("/order-service/order/1000,1001,1002,1003,1004,1005,1006").
with("/order-service/order/123456,123457,123458").
and_return(response)

orders = Nacre::API::Order.all
Expand All @@ -110,9 +110,9 @@

order = orders.first
order.should be_a(Nacre::API::Order)
order.id.should == 1008
order.identity["sku"].should == "SKU0001"
#order.orderTypeId.should == 1 #TODO uncamelize this
order.id.should == 123456
order.reference.should == 'order#001'
order.currency.accounting_currency_code.should == 'GBP'
end
end
end
Expand Down
264 changes: 264 additions & 0 deletions spec/fixtures/json/order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
{
"response": [
{
"id": 123456,
"parentOrderId" : 123455,
"orderTypeCode": "PO",
"reference": "order#001",
"acknowledged": 1,
"orderStatus": {
"orderStatusId": 6,
"name": "Pending PO"
},
"stockStatusCode": "NON",
"allocationStatusCode": "ANR",
"placedOn": "2011-06-29T11:12:24.000+01:00",
"createdOn": "2011-06-29T11:12:24.000+01:00",
"createdById": 200,
"priceListId": 1,
"priceModeCode": "EXC",
"delivery": {
"deliveryDate": "2011-07-08T00:00:00.000+01:00",
"shippingMethodId": 1
},
"invoices": [
{
"invoiceReference": "",
"taxDate": "2011-06-29T00:00:00.000+01:00",
"dueDate": "2011-07-29T00:00:00.000+01:00"
}
],
"currency": {
"accountingCurrencyCode": "GBP",
"orderCurrencyCode": "GBP",
"exchangeRate": "1.000000"
},
"totalValue": {
"net": "50.00",
"taxAmount": "10.00"
},
"assignment": {
"current": {
"staffOwnerContactId": 200,
"projectId": 1,
"channelId": 2,
"leadSourceId": 4,
"teamId": 2
}
},
"parties": {
"supplier": {
"contactId": 901,
"addressFullName": "Mr Drink",
"companyName": "Drink Supplies",
"addressLine1": "1 Main Road",
"addressLine2": "Out Of Town",
"addressLine3": "Bristol",
"addressLine4": "Avon",
"postalCode": "bs99 9sb",
"country": "United Kingdom",
"telephone": "01234 987654",
"mobileTelephone": "",
"email": "[email protected]"
},
"delivery": {
"addressFullName": "",
"companyName": "wacCorp",
"addressLine1": "Brightpearl HQ",
"addressLine2": "",
"addressLine3": "Bristol",
"addressLine4": "",
"postalCode": "BS2 9AG",
"country": "United Kingdom",
"telephone": "01234 567890",
"mobileTelephone": "",
"email": "[email protected]"
},
"billing": {
"contactId": 901,
"addressFullName": "",
"companyName": "wacCorp",
"addressLine1": "Brightpearl HQ",
"addressLine2": "",
"addressLine3": "Bristol",
"addressLine4": "",
"postalCode": "BS2 9AG",
"country": "United Kingdom",
"telephone": "01234 567890",
"mobileTelephone": "",
"email": "[email protected]"
}
},
"orderRows": {
"152": {
"orderRowSequence": "5",
"productId": 1011,
"productName": "Product C",
"productSku": "SKU1000",
"quantity": {
"magnitude": "2.00"
},
"rowValue": {
"taxRate": "20.00",
"taxCode": "T20",
"rowNet": {
"currencyCode": "GBP",
"value": "0.0000"
},
"rowTax": {
"currencyCode": "GBP",
"value": "0.00"
}
},
"productOptions": {
"Size": "Medium"
},
"nominalCode": "4000",
"composition": {
"bundleParent": false,
"bundleChild": true,
"parentOrderRowId": 149
}
},
"147": {
"orderRowSequence": "0",
"productId": 1008,
"productName": "Product B",
"productSku": "SKU0001",
"quantity": {
"magnitude": "1.00"
},
"rowValue": {
"taxRate": "20.00",
"taxCode": "T20",
"rowNet": {
"currencyCode": "GBP",
"value": "83.3333"
},
"rowTax": {
"currencyCode": "GBP",
"value": "16.67"
}
},
"nominalCode": "4000",
"composition": {
"bundleParent": false,
"bundleChild": false,
"parentOrderRowId": 0
}
},
"148": {
"orderRowSequence": "1",
"productId": 1009,
"productName": "Product C",
"productSku": "SKU1000",
"quantity": {
"magnitude": "5.00"
},
"rowValue": {
"taxRate": "20.00",
"taxCode": "T20",
"rowNet": {
"currencyCode": "GBP",
"value": "8.3333"
},
"rowTax": {
"currencyCode": "GBP",
"value": "8.33"
}
},
"productOptions": {
"Size": "Large"
},
"nominalCode": "4000",
"composition": {
"bundleParent": false,
"bundleChild": false,
"parentOrderRowId": 0
}
},
"149": {
"orderRowSequence": "2",
"productId": 1014,
"productName": "Bundle",
"productSku": "",
"quantity": {
"magnitude": "1.00"
},
"rowValue": {
"taxRate": "20.00",
"taxCode": "T20",
"rowNet": {
"currencyCode": "GBP",
"value": "12.5000"
},
"rowTax": {
"currencyCode": "GBP",
"value": "2.50"
}
},
"nominalCode": "4000",
"composition": {
"bundleParent": true,
"bundleChild": false,
"parentOrderRowId": 0
}
},
"150": {
"orderRowSequence": "3",
"productId": 1008,
"productName": "Product B",
"productSku": "SKU0001",
"quantity": {
"magnitude": "5.00"
},
"rowValue": {
"taxRate": "20.00",
"taxCode": "T20",
"rowNet": {
"currencyCode": "GBP",
"value": "0.0000"
},
"rowTax": {
"currencyCode": "GBP",
"value": "0.00"
}
},
"nominalCode": "4000",
"composition": {
"bundleParent": false,
"bundleChild": true,
"parentOrderRowId": 149
}
},
"151": {
"orderRowSequence": "4",
"productId": 1010,
"productName": "Product D",
"productSku": "",
"quantity": {
"magnitude": "3.00"
},
"rowValue": {
"taxRate": "20.00",
"taxCode": "T20",
"rowNet": {
"currencyCode": "GBP",
"value": "0.0000"
},
"rowTax": {
"currencyCode": "GBP",
"value": "0.00"
}
},
"nominalCode": "4000",
"composition": {
"bundleParent": false,
"bundleChild": true,
"parentOrderRowId": 149
}
}
}
}
]
}
Loading

0 comments on commit 9efd14c

Please sign in to comment.