-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from LucasRouckhout/improvement/allow_updating_…
…invoices Improvement/allow updating invoices
- Loading branch information
Showing
3 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build exclude | ||
// +build exclude | ||
|
||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,13 +39,13 @@ func TestInvoiceFeed(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestInvoiceAdd(t *testing.T) { | ||
func TestInvoiceAddAndUpdate(t *testing.T) { | ||
if os.Getenv("TWIKEY_API_KEY") == "" { | ||
t.Skip("No TWIKEY_API_KEY available") | ||
} | ||
|
||
c := newTestClient() | ||
t.Run("Invoice", func(t *testing.T) { | ||
t.Run("InvoiceAddAndUpdate", func(t *testing.T) { | ||
invoice, err := c.InvoiceAdd(context.Background(), &NewInvoiceRequest{ | ||
Invoice: &Invoice{ | ||
Number: "123", | ||
|
@@ -72,7 +72,8 @@ func TestInvoiceAdd(t *testing.T) { | |
t.Log("New invoice", invoice.Id) | ||
} | ||
|
||
cnote, err := c.InvoiceAdd(context.Background(), &NewInvoiceRequest{ | ||
ctx := context.Background() | ||
cnote, err := c.InvoiceAdd(ctx, &NewInvoiceRequest{ | ||
Invoice: &Invoice{ | ||
Number: "124", | ||
RelatedInvoice: "123", | ||
|
@@ -95,5 +96,58 @@ func TestInvoiceAdd(t *testing.T) { | |
} else { | ||
t.Log("New CreditNote", cnote.Id) | ||
} | ||
|
||
if err := c.InvoiceUpdate(ctx, &UpdateInvoiceRequest{ | ||
ID: invoice.Id, | ||
Title: "Some updated title", | ||
}); err != nil { | ||
if err != nil { | ||
t.Error(err) | ||
} else { | ||
t.Log("Updated invoice", cnote.Id) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func TestInvoiceUpdateWithInvalidRequest(t *testing.T) { | ||
if os.Getenv("TWIKEY_API_KEY") == "" { | ||
t.Skip("No TWIKEY_API_KEY available") | ||
} | ||
|
||
c := newTestClient() | ||
t.Run("InvoiceUpdateWithInvalidRequest", func(t *testing.T) { | ||
invoice, err := c.InvoiceAdd(context.Background(), &NewInvoiceRequest{ | ||
Invoice: &Invoice{ | ||
Number: "123123", | ||
Title: "TestInvoice 123123", | ||
Date: "2021-01-01", | ||
Duedate: "2021-03-01", | ||
Remittance: "123123", | ||
Amount: 10.00, | ||
Customer: &Customer{ | ||
CustomerNumber: "123123", | ||
Email: "[email protected]", | ||
Address: "Derbystraat 43", | ||
City: "Gent", | ||
Zip: "9051", | ||
Country: "BE", | ||
Language: "nl", | ||
}, | ||
}, | ||
Origin: "Go-Test", | ||
}) | ||
if err != nil { | ||
t.Error(err) | ||
} else { | ||
t.Log("New invoice", invoice.Id) | ||
} | ||
|
||
ctx := context.Background() | ||
if err := c.InvoiceUpdate(ctx, &UpdateInvoiceRequest{ | ||
Title: "Some updated title", | ||
}); err == nil { | ||
t.Error("Update invoice call did not return an error even though we send no ID") | ||
} | ||
}) | ||
} |