From 1c22b359ff0ff2443263470e08e0ddab02cf443f Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 28 Aug 2024 08:26:40 +0530 Subject: [PATCH 1/5] [Automated] Update the toml files --- ballerina/Ballerina.toml | 2 +- ballerina/Dependencies.toml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index ad4a7d3..401337f 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -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"] diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 4f52392..00ada8c 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -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"} @@ -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"}, @@ -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"} @@ -296,7 +296,7 @@ modules = [ [[package]] org = "ballerinax" name = "dayforce" -version = "0.1.0" +version = "0.1.1" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "test"}, From 0f92710041169b776c2ca6b7f3f6b8a77a29ffbd Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 4 Sep 2024 21:52:43 +0530 Subject: [PATCH 2/5] Implement mock service --- ballerina/tests/mock_service.bal | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ballerina/tests/mock_service.bal diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal new file mode 100644 index 0000000..3395953 --- /dev/null +++ b/ballerina/tests/mock_service.bal @@ -0,0 +1,42 @@ +// 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 { + "employeeId": "123", + "employeeName": "John Doe", + "employeeAge": 30, + "employeeSalary": 1000.0 + }; + } +}; + +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(); +} From 02dbd8bdc21c8d0ab8432e6f932a696d93b189a6 Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 4 Sep 2024 21:55:24 +0530 Subject: [PATCH 3/5] Refactor tests --- ballerina/tests/mock_service.bal | 2 +- ballerina/tests/{test.bal => tests.bal} | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) rename ballerina/tests/{test.bal => tests.bal} (54%) diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 3395953..bea28b8 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -23,7 +23,7 @@ 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 { - "employeeId": "123", + "employeeId": "42199", "employeeName": "John Doe", "employeeAge": 30, "employeeSalary": 1000.0 diff --git a/ballerina/tests/test.bal b/ballerina/tests/tests.bal similarity index 54% rename from ballerina/tests/test.bal rename to ballerina/tests/tests.bal index 785268a..92b5907 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/tests.bal @@ -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"); } From 183e594da3bdeb0f26f612757c1f3dc823e27b58 Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 4 Sep 2024 22:06:53 +0530 Subject: [PATCH 4/5] Add README.md --- ballerina/tests/README.md | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 ballerina/tests/README.md diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md new file mode 100644 index 0000000..ba40ecf --- /dev/null +++ b/ballerina/tests/README.md @@ -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="" +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= +export PASSWORD= +``` + +For Windows: + +```bash +setx IS_LIVE_SERVER true +setx USERNAME +setx PASSWORD +``` + +Then, run the following command to execute the tests: + +```bash +./gradlew clean test +``` From a74194ca7e85a6b21244d1d85654387e1d87daba Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 4 Sep 2024 22:17:57 +0530 Subject: [PATCH 5/5] Add minor fix --- ballerina/Dependencies.toml | 8 ++++++++ ballerina/tests/mock_service.bal | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 00ada8c..bd61d23 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -211,6 +211,9 @@ dependencies = [ {org = "ballerina", name = "lang.value"}, {org = "ballerina", name = "observe"} ] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] [[package]] org = "ballerina" @@ -251,6 +254,9 @@ dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} ] +modules = [ + {org = "ballerina", packageName = "os", moduleName = "os"} +] [[package]] org = "ballerina" @@ -299,6 +305,8 @@ name = "dayforce" 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"} ] diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index bea28b8..17d42fa 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -23,10 +23,9 @@ 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 { - "employeeId": "42199", - "employeeName": "John Doe", - "employeeAge": 30, - "employeeSalary": 1000.0 + Data: { + EmployeeNumber: xRefCode + } }; } };