-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathapa_product_spec.rb
132 lines (103 loc) · 4.36 KB
/
apa_product_spec.rb
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
# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'date'
describe "ONIX::APAProduct" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "product.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
it "should provide read access to attributes" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.record_reference.should eql("365-9780194351898")
@apa.notification_type.should eql(3)
@apa.product_form.should eql("BC")
@apa.number_of_pages.should eql(100)
@apa.bic_main_subject.should eql("EB")
@apa.publishing_status.should eql(4)
@apa.publication_date.should eql(Date.civil(1998,9,1))
@apa.pack_quantity.should eql(12)
end
it "should provide write access to attributes" do
apa = ONIX::APAProduct.new
apa.notification_type = 3
apa.to_xml.to_s.include?("<NotificationType>03</NotificationType>").should be_true
apa.record_reference = "365-9780194351898"
apa.to_xml.to_s.include?("<RecordReference>365-9780194351898</RecordReference>").should be_true
apa.product_form = "BC"
apa.to_xml.to_s.include?("<ProductForm>BC</ProductForm>").should be_true
apa.number_of_pages = 100
apa.to_xml.to_s.include?("<NumberOfPages>100</NumberOfPages>").should be_true
apa.bic_main_subject = "EB"
apa.to_xml.to_s.include?("<BICMainSubject>EB</BICMainSubject>").should be_true
apa.publishing_status = 4
apa.to_xml.to_s.include?("<PublishingStatus>04</PublishingStatus>").should be_true
apa.publication_date = Date.civil(1998,9,1)
apa.to_xml.to_s.include?("<PublicationDate>19980901</PublicationDate>").should be_true
apa.pack_quantity = 12
apa.to_xml.to_s.include?("<PackQuantity>12</PackQuantity>").should be_true
end
end
describe ONIX::APAProduct, "series method" do
it "should set the nested series value on the underlying product class" do
apa = ONIX::APAProduct.new
apa.series = "Harry Potter"
apa.series.should eql("Harry Potter")
apa.to_xml.to_s.include?("<TitleOfSeries>Harry Potter</TitleOfSeries>").should be_true
end
end
describe ONIX::APAProduct, "price method" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "usd.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
it "should return the first price in the file, regardless of type" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.price.should eql(BigDecimal.new("99.95"))
end
end
describe ONIX::APAProduct, "rrp_exc_sales_tax method" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "usd.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
it "should return the first price in the file of type 1" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.rrp_exc_sales_tax.should eql(BigDecimal.new("99.95"))
end
end
describe ONIX::APAProduct, "proprietry_discount_code_for_rrp method" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "product.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
it "should return the first price in the file, regardless of type" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.proprietry_discount_code_for_rrp.should eql("123")
end
end
describe ONIX::APAProduct, "proprietry_discount_code_for_rrp= method" do
before(:each) do
@data_path = File.join(File.dirname(__FILE__),"..","data")
file1 = File.join(@data_path, "product.xml")
@doc = Nokogiri::XML::Document.parse(File.read(file1))
@product_node = @doc.root
end
it "should set the discount code on the RRP" do
@product = ONIX::Product.from_xml(@product_node.to_s)
@apa = ONIX::APAProduct.new(@product)
@apa.proprietry_discount_code_for_rrp="123"
@apa.to_xml.to_s.include?("<DiscountCode>123</DiscountCode>").should be_true
end
end