|
| 1 | +package serverscom |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func TestInvoicesCollection(t *testing.T) { |
| 10 | + g := NewGomegaWithT(t) |
| 11 | + |
| 12 | + ts, client := newFakeServer(). |
| 13 | + WithRequestPath("/billing/invoices"). |
| 14 | + WithRequestMethod("GET"). |
| 15 | + WithResponseBodyStubInline(`[]`). |
| 16 | + WithResponseCode(200). |
| 17 | + Build() |
| 18 | + |
| 19 | + defer ts.Close() |
| 20 | + |
| 21 | + collection := client.Invoices.Collection() |
| 22 | + |
| 23 | + ctx := context.TODO() |
| 24 | + |
| 25 | + list, err := collection.List(ctx) |
| 26 | + |
| 27 | + g.Expect(err).To(BeNil()) |
| 28 | + g.Expect(list).To(BeEmpty()) |
| 29 | + g.Expect(collection.HasNextPage()).To(Equal(false)) |
| 30 | + g.Expect(collection.HasPreviousPage()).To(Equal(false)) |
| 31 | + g.Expect(collection.HasFirstPage()).To(Equal(false)) |
| 32 | + g.Expect(collection.HasLastPage()).To(Equal(false)) |
| 33 | +} |
| 34 | + |
| 35 | +func TestGetInvoice(t *testing.T) { |
| 36 | + g := NewGomegaWithT(t) |
| 37 | + |
| 38 | + ts, client := newFakeServer(). |
| 39 | + WithRequestPath("/billing/invoices/9qzw9Hj4"). |
| 40 | + WithRequestMethod("GET"). |
| 41 | + WithResponseBodyStubFile("fixtures/invoices/get_response.json"). |
| 42 | + WithResponseCode(200). |
| 43 | + Build() |
| 44 | + |
| 45 | + defer ts.Close() |
| 46 | + |
| 47 | + ctx := context.TODO() |
| 48 | + |
| 49 | + invoice, err := client.Invoices.GetBillingInvoice(ctx, "9qzw9Hj4") |
| 50 | + |
| 51 | + g.Expect(err).To(BeNil()) |
| 52 | + g.Expect(invoice).ToNot(BeNil()) |
| 53 | + g.Expect(invoice.ID).To(Equal("9qzw9Hj4")) |
| 54 | + g.Expect(invoice.Number).To(Equal(int64(843071))) |
| 55 | + g.Expect(invoice.ParentID).To(BeNil()) |
| 56 | + g.Expect(invoice.Status).To(Equal("paid")) |
| 57 | + g.Expect(invoice.Date).To(Equal("2024-06-23")) |
| 58 | + g.Expect(invoice.Type).To(Equal("invoice")) |
| 59 | + g.Expect(invoice.TotalDue).To(Equal(11.90)) |
| 60 | + g.Expect(invoice.Currency).To(Equal("EUR")) |
| 61 | + g.Expect(invoice.CsvUrl).To(Equal("url")) |
| 62 | + g.Expect(invoice.PdfUrl).To(Equal("url")) |
| 63 | +} |
0 commit comments