Skip to content

Commit

Permalink
PETOSS-561 Update existing tests in Dotnet SDK to work with PRISM Moc…
Browse files Browse the repository at this point in the history
…k Server (#561)

Co-authored-by: Vignesh Kennadi <[email protected]>
  • Loading branch information
vigneshk-tw and Vignesh Kennadi authored Sep 26, 2024
1 parent 18684e2 commit 165ed16
Show file tree
Hide file tree
Showing 21 changed files with 1,869 additions and 232 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The Xero-NetStandard SDK makes it easy for developers to access Xero's APIs in t
- [API Clients](#api-clients)
- [Helper Methods](#helper-methods)
- [Usage Examples](#usage-examples)
- [Running Test(s) in Local](#running-tests-in-local)
- [SDK conventions](#sdk-conventions)
- [Contributing](#contributing)

Expand Down Expand Up @@ -796,6 +797,16 @@ await FilesApi.DeleteFileAssociationAsync(accessToken, xeroTenantId, fileIdGuid,
```

---
## Running Test(s) in Local
For Running Test cases PRISM Mock Server needs to be started in the local machine.
Steps to Run Test(s)
* Install PRISM from npm using the command: **npm install -g @stoplight/prism-cli**
* Verify Installation: **prism --version**
* Navigate to **Xero-NetStandard--> Xero.NetStandard.OAuth2.Test--> util** folder in the terminal
* Execute the script **./start-prism.sh**
* This will start the PRISM Server in Local
* Run **dotnet test** to run the dotnet test cases.

## SDK conventions

## Security (state check & Jwt validation)
Expand Down
226 changes: 192 additions & 34 deletions Xero.NetStandard.OAuth2.Test/Api/AccountingApiTests.cs

Large diffs are not rendered by default.

55 changes: 45 additions & 10 deletions Xero.NetStandard.OAuth2.Test/Api/PayrollAuApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ public void InstanceTest()
[Fact]
public async Task CreateEmployeeTest()
{
List<Employee> employee =
new List<Employee> { new Employee() };
var response = await instance.CreateEmployeeAsync(accessToken, xeroTenantId, employee);
List<Employee> employees = new List<Employee> { new Employee()
{
FirstName = "Adam",
LastName = "Adamson",
DateOfBirth = new DateTime(2000, 10, 10)
}};
var response = await instance.CreateEmployeeAsync(accessToken, xeroTenantId, employees);
Assert.IsType<Employees>(response);
}

Expand Down Expand Up @@ -112,7 +116,10 @@ public async Task CreatePayItemTest()
[Fact]
public async Task CreatePayRunTest()
{
List<PayRun> payRun = new List<PayRun> { new PayRun() };
List<PayRun> payRun = new List<PayRun> { new PayRun()
{
PayrollCalendarID = Guid.Parse("00000000-0000-0000-0000-000000000000")
}};
var response = await instance.CreatePayRunAsync(accessToken, xeroTenantId, payRun);
Assert.IsType<PayRuns>(response);
}
Expand All @@ -134,7 +141,10 @@ public async Task CreatePayrollCalendarTest()
[Fact]
public async Task CreateSuperfundTest()
{
List<SuperFund> superFund = new List<SuperFund> { new SuperFund() };
List<SuperFund> superFund = new List<SuperFund> { new SuperFund()
{
Type = SuperFundType.REGULATED
}};
var response = await instance.CreateSuperfundAsync(accessToken, xeroTenantId, superFund);
Assert.IsType<SuperFunds>(response);
}
Expand All @@ -145,7 +155,14 @@ public async Task CreateSuperfundTest()
[Fact]
public async Task CreateTimesheetTest()
{
List<Timesheet> timesheet = new List<Timesheet> { new Timesheet() };
var startDate = new DateTime(2020, 10, 23);
var endDate = new DateTime(2020, 10, 30);
List<Timesheet> timesheet = new List<Timesheet> { new Timesheet()
{
EmployeeID = Guid.Parse("00000000-0000-0000-0000-000000000000"),
StartDate = startDate,
EndDate = endDate,
}};
var response = await instance.CreateTimesheetAsync(accessToken, xeroTenantId, timesheet);
Assert.IsType<Timesheets>(response);
}
Expand Down Expand Up @@ -354,7 +371,12 @@ public async Task GetTimesheetsTest()
public async Task UpdateEmployeeTest()
{
Guid employeeId = AutoFaker.Generate<Guid>();
List<Employee> employee = new List<Employee> { new Employee() };
List<Employee> employee = new List<Employee> { new Employee()
{
FirstName = "Adam",
LastName = "Adamson",
DateOfBirth = new DateTime(2000, 10, 10)
}};
string idempotencyKey = AutoFaker.Generate<string>();
var response = await instance.UpdateEmployeeAsync(accessToken, xeroTenantId, employeeId, employee, idempotencyKey);
Assert.IsType<Employees>(response);
Expand All @@ -380,7 +402,10 @@ public async Task UpdatePayRunTest()
{
Guid payRunID = AutoFaker.Generate<Guid>();
string idempotencyKey = AutoFaker.Generate<string>();
List<PayRun> payRun = new List<PayRun> { new PayRun() };
List<PayRun> payRun = new List<PayRun> { new PayRun()
{
PayrollCalendarID = Guid.Parse("00000000-0000-0000-0000-000000000000")
}};
var response = await instance.UpdatePayRunAsync(accessToken, xeroTenantId, payRunID, payRun, idempotencyKey);
Assert.IsType<PayRuns>(response);
}
Expand All @@ -406,7 +431,10 @@ public async Task UpdateSuperfundTest()
{
Guid superFundID = AutoFaker.Generate<Guid>();
string idempotencyKey = AutoFaker.Generate<string>();
List<SuperFund> superFund = new List<SuperFund> { new SuperFund() };
List<SuperFund> superFund = new List<SuperFund> { new SuperFund()
{
Type = SuperFundType.REGULATED
}};
var response = await instance.UpdateSuperfundAsync(accessToken, xeroTenantId, superFundID, superFund, idempotencyKey);
Assert.IsType<SuperFunds>(response);
}
Expand All @@ -419,7 +447,14 @@ public async Task UpdateTimesheetTest()
{
Guid timesheetID = AutoFaker.Generate<Guid>();
string idempotencyKey = AutoFaker.Generate<string>();
List<Timesheet> timesheet = new List<Timesheet> { new Timesheet() };
var startDate = new DateTime(2020, 10, 23);
var endDate = new DateTime(2020, 10, 30);
List<Timesheet> timesheet = new List<Timesheet> { new Timesheet()
{
EmployeeID = Guid.Parse("00000000-0000-0000-0000-000000000000"),
StartDate = startDate,
EndDate = endDate,
}};
var response = await instance.UpdateTimesheetAsync(accessToken, xeroTenantId, timesheetID, timesheet, idempotencyKey);
Assert.IsType<Timesheets>(response);
}
Expand Down
6 changes: 3 additions & 3 deletions Xero.NetStandard.OAuth2.Test/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"XeroConfiguration": {
"AccountingBaseUrl": "https://25faf04a-c71e-40e7-b7ce-f1fae0149465.mock.pstmn.io/api.xro/2.0",
"BankfeedsBaseUrl": "https://3e140044-4914-47dd-b4e1-df0cc040a44f.mock.pstmn.io/bankfeeds.xro/1.0",
"PayrollAuBaseUrl": "https://5f9f95f1-25c8-40dd-8b10-8192c658dd79.mock.pstmn.io/payroll.xro/1.0"
"AccountingBaseUrl": "http://127.0.0.1:4010",
"BankfeedsBaseUrl": "http://127.0.0.1:4013",
"PayrollAuBaseUrl": "http://127.0.0.1:4017"
}
}
9 changes: 9 additions & 0 deletions Xero.NetStandard.OAuth2.Test/util/start-prism.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero_accounting.yaml --host 127.0.0.1 --port 4010 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-app-store.yaml --host 127.0.0.1 --port 4011 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero_assets.yaml --host 127.0.0.1 --port 4012 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero_bankfeeds.yaml --host 127.0.0.1 --port 4013 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-finance.yaml --host 127.0.0.1 --port 4014 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-payroll-uk.yaml --host 127.0.0.1 --port 4015 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-payroll-nz.yaml --host 127.0.0.1 --port 4016 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-payroll-au.yaml --host 127.0.0.1 --port 4017 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-projects.yaml --host 127.0.0.1 --port 4018
Loading

0 comments on commit 165ed16

Please sign in to comment.