Skip to content

Commit

Permalink
Missing EPrint action in Invoice Connector (#301)
Browse files Browse the repository at this point in the history
* Added missing EPrint action to InvoiceConnector

* EPrint returns Invoices not PDF

* Fix Invoice Print tests

Added/updated tests had errors

---------

Co-authored-by: adamelfstrom <[email protected]>
  • Loading branch information
yosz and adamelfstrom authored Oct 7, 2024
1 parent 898778e commit 2ea0b51
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
48 changes: 45 additions & 3 deletions FortnoxSDK.Tests/ConnectorTests/InvoiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,55 @@ public async Task Test_DueDate()
#endregion Delete arranged resources
}

[TestMethod]
[Ignore("Fails with error 'Kan inte skicka dokument om inte företaget är registrerat'")]
public async Task Test_EPrint()
{
#region Arrange
var cc = FortnoxClient.CustomerConnector;
var ac = FortnoxClient.ArticleConnector;
var tmpCustomer = await cc.CreateAsync(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis", Email = "[email protected]" });
var tmpArticle = await ac.CreateAsync(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 });
#endregion Arrange

var connector = FortnoxClient.InvoiceConnector;

var newInvoice = new Invoice()
{
CustomerNumber = tmpCustomer.CustomerNumber,
InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20",
DueDate = new DateTime(2019, 2, 20), //"2019-02-20",
InvoiceType = InvoiceType.CashInvoice,
PaymentWay = PaymentWay.Cash,
Comments = "TestInvoice",
InvoiceRows = new List<InvoiceRow>()
{
new InvoiceRow(){ ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100},
new InvoiceRow(){ ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100},
new InvoiceRow(){ ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100}
}
};

var createdInvoice = await connector.CreateAsync(newInvoice);

var printedInvoice = await connector.EPrintAsync(createdInvoice.DocumentNumber);
Assert.AreEqual(printedInvoice.DocumentNumber, createdInvoice.DocumentNumber);

await connector.CancelAsync(createdInvoice.DocumentNumber);

#region Delete arranged resources
await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber);
// await FortnoxClient.ArticleConnector.DeleteAsync(tmpArticle.ArticleNumber);
#endregion Delete arranged resources
}

[TestMethod]
public async Task Test_Print()
{
#region Arrange
var cc = FortnoxClient.CustomerConnector;
var ac = FortnoxClient.ArticleConnector;
var tmpCustomer = await cc.CreateAsync(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" });
var tmpCustomer = await cc.CreateAsync(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis", Email = "[email protected]" });
var tmpArticle = await ac.CreateAsync(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 });
#endregion Arrange

Expand Down Expand Up @@ -222,7 +264,7 @@ public async Task Test_Print()

#region Delete arranged resources
await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber);
//FortnoxClient.ArticleConnector.Delete(tmpArticle.ArticleNumber);
//await FortnoxClient.ArticleConnector.DeleteAsync(tmpArticle.ArticleNumber);
#endregion Delete arranged resources
}

Expand Down Expand Up @@ -261,7 +303,7 @@ public async Task Test_Email()

#region Delete arranged resources
await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber);
//FortnoxClient.ArticleConnector.Delete(tmpArticle.ArticleNumber);
//await FortnoxClient.ArticleConnector.DeleteAsync(tmpArticle.ArticleNumber);
#endregion Delete arranged resources
}

Expand Down
2 changes: 1 addition & 1 deletion FortnoxSDK/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public static bool IsDownloadAction(this Action action)
case Action.Print:
case Action.PrintReminder:
case Action.Preview:
case Action.EPrint:
return true;
default:
return false;
Expand All @@ -81,6 +80,7 @@ public static HttpMethod GetMethod(this Action action)
return HttpMethod.Put;
case Action.Email:
case Action.EInvoice:
case Action.EPrint:
return HttpMethod.Get;
default:
return HttpMethod.Put;
Expand Down
5 changes: 5 additions & 0 deletions FortnoxSDK/Connectors/InvoiceConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public async Task<Invoice> EInvoiceAsync(long? id)
return await DoActionAsync(id.ToString(), Action.EInvoice).ConfigureAwait(false);
}

public async Task<Invoice> EPrintAsync(long? id)
{
return await DoActionAsync(id.ToString(), Action.EPrint).ConfigureAwait(false);
}

public async Task<byte[]> PrintAsync(long? id)
{
return await DoDownloadActionAsync(id.ToString(), Action.Print).ConfigureAwait(false);
Expand Down
1 change: 1 addition & 0 deletions FortnoxSDK/Interfaces/IInvoiceConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface IInvoiceConnector : IEntityConnector
Task<Invoice> CreditInvoiceAsync(long? id);
Task<Invoice> EmailAsync(long? id);
Task<Invoice> EInvoiceAsync(long? id);
Task<Invoice> EPrintAsync(long? id);
Task<byte[]> PrintAsync(long? id);
Task<byte[]> PrintReminderAsync(long? id);
Task<Invoice> ExternalPrintAsync(long? id);
Expand Down

0 comments on commit 2ea0b51

Please sign in to comment.