Skip to content

Commit

Permalink
Merge pull request #5 from NipunaRanasinghe/test-fixes
Browse files Browse the repository at this point in the history
Fix test failures
  • Loading branch information
NipunaRanasinghe authored Sep 4, 2024
2 parents 6b0deea + a74194c commit 4ed220d
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
distribution = "2201.8.0"
org = "ballerinax"
name = "dayforce"
version = "0.1.0"
version = "0.1.1"
authors = ["Ballerina"]
repository = "https://github.com/ballerina-platform/module-ballerinax-dayforce"
keywords = ["HCM", "Workforce Management", "HRIS"]
Expand Down
16 changes: 12 additions & 4 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.6.2"
version = "2.6.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -61,7 +61,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.10.13"
version = "2.10.15"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -93,7 +93,7 @@ modules = [
[[package]]
org = "ballerina"
name = "io"
version = "1.6.0"
version = "1.6.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand Down Expand Up @@ -211,6 +211,9 @@ dependencies = [
{org = "ballerina", name = "lang.value"},
{org = "ballerina", name = "observe"}
]
modules = [
{org = "ballerina", packageName = "log", moduleName = "log"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -251,6 +254,9 @@ dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "os", moduleName = "os"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -296,9 +302,11 @@ modules = [
[[package]]
org = "ballerinax"
name = "dayforce"
version = "0.1.0"
version = "0.1.1"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "os"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "url"}
]
Expand Down
92 changes: 92 additions & 0 deletions ballerina/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Running Tests

## Prerequisites

You need to obtain user credentials to run the tests against the Dayforce live server.

To obtain this, refer to the [Setup guide](https://github.com/ballerina-platform/module-ballerinax-dayforce/blob/main/ballerina/Module.md).

## Test Environments

There are two test environments for running the `dayforce` connector tests. The default environment is a mock server for the Dayforce API. The other environment is the Dayforce live server.

You can run the tests in either of these environments, and each has its own compatible set of tests.

| Test Groups | Environment |
|-------------|----------------------------------------------------|
| mock_tests | Mock server for Dayforce API (Default Environment) |
| live_tests | Dayforce API |

## Running Tests in the Mock Server

To execute the tests on the mock server, ensure that the `IS_LIVE_SERVER` environment variable is either set to `false` or left unset before initiating the tests.

This environment variable can be configured within the `Config.toml` file located in the `tests` directory or specified as an environment variable.

### Using a `Config.toml` File

Create a `Config.toml` file in the `tests` directory with the following content:

```toml
isLiveServer = false
```

### Using Environment Variables

Alternatively, you can set the environment variable directly.

For Linux or macOS:

```bash
export IS_LIVE_SERVER=false
```

For Windows:

```bash
setx IS_LIVE_SERVER false
```

Then, run the following command to execute the tests:

```bash
./gradlew clean test
```

## Running Tests Against the Dayforce Live API

### Using a `Config.toml` File

Create a `Config.toml` file in the `tests` directory and add your authentication credentials:

```toml
isLiveServer = true
username="<your-username>"
password="<your-password>"
```

### Using Environment Variables

Alternatively, you can set your authentication credentials as environment variables.

For Linux or macOS:

```bash
export IS_LIVE_SERVER=true
export USERNAME=<your-username>
export PASSWORD=<your-password>
```

For Windows:

```bash
setx IS_LIVE_SERVER true
setx USERNAME <your-username>
setx PASSWORD <your-password>
```

Then, run the following command to execute the tests:

```bash
./gradlew clean test
```
41 changes: 41 additions & 0 deletions ballerina/tests/mock_service.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/http;
import ballerina/log;

listener http:Listener httpListener = new (9090);

http:Service mockService = service object {

isolated resource function get [string clientNamespace]/V1/Employees/[string xRefCode](string? contextDate = (), string? expand = (), string? contextDateRangeFrom = (), string? contextDateRangeTo = (), string? amfEntity = (), string? amfLevel = (), string? amfLevelValue = ()) returns Payload_Employee|error {
return {
Data: {
EmployeeNumber: xRefCode
}
};
}
};

function init() returns error? {
if isLiveServer {
log:printInfo("Skiping mock server initialization as the tests are running on live server");
return;
}
log:printInfo("Initiating mock server");
check httpListener.attach(mockService, "/");
check httpListener.'start();
}
20 changes: 17 additions & 3 deletions ballerina/tests/test.bal → ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@
// specific language governing permissions and limitations
// under the License.

import ballerina/os;
import ballerina/test;

configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true";
configurable string username = isLiveServer ? os:getEnv("USERNAME") : "test";
configurable string password = isLiveServer ? os:getEnv("PASSWORD") : "test";
configurable string serviceUrl = isLiveServer ? "https://ustest241-services.dayforcehcm.com/Api" : "http://localhost:9090";

ConnectionConfig config = {
auth: {
username,
password
}
};

Client dayforce = check new (config, serviceUrl);

@test:Config {}
isolated function testGetEmployee() returns error? {
Client testClient = check new({auth: {username: "DFWSTest", password: "DFWSTest"}}, "https://ustest241-services.dayforcehcm.com/Api");
Payload_Employee employee = check testClient->/ddn/V1/Employees/'42199;
function testGetEmployee() returns error? {
Payload_Employee employee = check dayforce->/ddn/V1/Employees/'42199;
test:assertEquals(employee?.Data?.EmployeeNumber, "42199");
}

0 comments on commit 4ed220d

Please sign in to comment.