Guest User

Untitled

a guest
Jun 24th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. @IsTest
  2. private class InvoiceManagerTest {
  3. //GET
  4. @isTest static string testGetInvoice() {
  5. Invoice__c invoice = createInvoice();
  6. String query = '?customerId='+ invoice.customerId__c + '&month=' + invoice.invoiceDate__c.month();
  7. // Set up a test request
  8. RestRequest request = new RestRequest();
  9. request.requestUri =
  10. 'https://aaXX.salesforce.com/services/apexrest/invoices/'+
  11. query;
  12.  
  13. request.httpMethod = 'GET';
  14. RestContext.request = request;
  15. // Call the method to test
  16. string thisInvoice = InvoiceManager.getInvoice();
  17. // Verify results
  18. System.assert(thisInvoice != null);
  19. System.assertEquals(
  20. ' {'+
  21. '"customerId": "1",'+
  22. '"addressId": "2018AA12",'+
  23. '"invoiceId": "00ec5a04a43c014aa9e8",'+
  24. '"invoiceType": "AdvancePayment",'+
  25. '"invoiceTypeLocalized": "Voorschot",'+
  26. '"invoiceDate": "2018-06-01T00:00:00",'+
  27. '"DueDate": "2018-06-01T00:00:00",'+
  28. '"invoiceNumber": "157005888",'+
  29. '"startDate": "2016-07-01T00:00:00",'+
  30. '"endDate": "2017-07-01T00:00:00",'+
  31. '"Description": "June 2018",'+
  32. '"amount": 100.10,'+
  33. '"vatAmount": 30.30,'+
  34. '"totalAmount": 130.40'+
  35. '}'
  36. , thisInvoice);
  37. }
  38.  
  39. // Helper method
  40. static Invoice__c createInvoice() {
  41. // Create test record
  42. Invoice__c invoiceTest = new Invoice__c(
  43. customerId__c = '1',
  44. addressId__c = '2018AA12',
  45. invoiceId__c = '00ec5a04a43c014aa9e8 ',
  46. invoiceType__c = 'AdvancePayment',
  47. invoiceTypeLocalized__c = 'Voorschot',
  48. invoiceDate__c = Date.valueOf('2018-06-01 00:00:00'),
  49. paymentDueDate__c = Date.valueOf('2018-06-08 00:00:00'),
  50. invoiceNumber__c = '157005888',
  51. startDate__c = Date.valueOf('2015-06-01 00:00:00'),
  52. endDate__c = Date.valueOf('2020-06-01 00:00:00'),
  53. periodDescription__c = 'June 2018',
  54. amount__c = 100.10,
  55. vatAmount__c = 30.30,
  56. totalAmount__c = 130.40 );
  57. insert invoiceTest;
  58. return invoiceTest;
  59. }
  60. }
Add Comment
Please, Sign In to add comment