spec/moip2/invoice_spec.rb in moip2-1.1.0 vs spec/moip2/invoice_spec.rb in moip2-1.2.0
- old
+ new
@@ -109,6 +109,76 @@
it { expect(result.invoices[0].account_id).to eq "MPA-MAROTO000000" }
it { expect(result.invoices[1].id).to eq "INV-635DC2BSHJ90" }
it { expect(result.invoices[1].account_id).to eq "MPA-MAROTO000000" }
end
end
+
+ describe "#find_all" do
+ context "when passing limit" do
+ subject(:response) do
+ VCR.use_cassette("list_invoices_limit") do
+ invoice_api.find_all(limit: 3)
+ end
+ end
+ it { expect(response).to_not be_nil }
+ it { expect(response.invoices.size).to eq(3) }
+ it { expect(response.invoices[0].id).to eq "INV-AF4D550CD9D1" }
+ it { expect(response.invoices[1].id).to eq "INV-BC7871A7EF46" }
+ it { expect(response.invoices[2].id).to eq "INV-AB6915F7AC98" }
+
+ end
+
+ context "when passing offset" do
+ subject(:response) do
+ VCR.use_cassette("list_invoices_limit_offset") do
+ invoice_api.find_all(limit: 10, offset: 4)
+ end
+ end
+ it { expect(response).to_not be_nil }
+ it { expect(response.invoices.size).to eq(10) }
+ it { expect(response._links.next.href).to eq("/invoices?limit=10\u0026offset=14") }
+ it { expect(response.invoices[0].id).to eq "INV-D2EC2F1D7D55" }
+ it { expect(response.invoices[1].id).to eq "INV-AF36FE78CFB6" }
+
+ end
+ end
+
+ context "when passing filters" do
+ subject(:response) do
+ VCR.use_cassette("find_all_invoices_filters") do
+ invoice_api.find_all(filters: { status: { in: ["SENT", "PAID"] } })
+ end
+ end
+
+ it "all invoices satisfy the filter constraint" do
+ expect(response.invoices).to satisfy do |invoices|
+ invoices.all? { |invoice| ["SENT", "PAID"].include?(invoice.status) }
+ end
+ end
+ end
+
+ context "when passing multiple filters" do
+ subject(:response) do
+ VCR.use_cassette("find_all_invoices_multi_filters") do
+ invoice_api.find_all(filters: {
+ status: { in: ["PAID", "WAITING"] },
+ amount: { bt: [9000, 12000] },
+ })
+ end
+ end
+
+ it { expect(response._links).not_to be_nil }
+
+ it "all invoices satisfy the status constraint" do
+ expect(response.invoices).to satisfy do |invoices|
+ invoices.all? { |invoice| ["PAID", "WAITING"].include?(invoice.status) }
+ end
+ end
+
+ it "all invoices satisfy the amount constraint" do
+ expect(response.invoices).to satisfy do |invoices|
+ invoices.all? { |invoice| invoice.amount.total.between?(9000, 12000) }
+ end
+ end
+ end
+
end