diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 1467939..1b222a4 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -13,3 +13,5 @@ jobs: if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-connector-template.yml@main secrets: inherit + with: + additional-build-flags: "-x :candid-examples:build -Pgroups=mock" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c564b59..694620f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,4 +16,4 @@ jobs: secrets: inherit with: repo-name: module-ballerinax-candid - additional-test-flags: -x test + additional-test-flags: -Pgroups=mock diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index 97b328e..433a7d8 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -12,4 +12,4 @@ jobs: secrets: inherit with: repo-name: module-ballerinax-candid - additional-test-flags: -x test + additional-test-flags: -Pgroups=mock diff --git a/.github/workflows/dev-stg-release.yml b/.github/workflows/dev-stg-release.yml index ad1498f..e1dfeec 100644 --- a/.github/workflows/dev-stg-release.yml +++ b/.github/workflows/dev-stg-release.yml @@ -19,4 +19,4 @@ jobs: secrets: inherit with: environment: ${{ github.event.inputs.environment }} - additional-publish-flags: -x test + additional-publish-flags: "-x :candid-examples:build -Pgroups=mock" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8fe0285..0562be5 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -13,4 +13,4 @@ jobs: uses: ballerina-platform/ballerina-standard-library/.github/workflows/pr-build-connector-template.yml@main secrets: inherit with: - additional-test-flags: -x test + additional-test-flags: -Pgroups=mock diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index caf9734..a36b1ac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,6 @@ jobs: with: package-name: candid package-org: ballerinax - additional-build-flags: "-x :candid-examples:build" - additional-release-flags: "-x test -x :candid-examples:build" - additional-publish-flags: "-x :candid-examples:build" + additional-build-flags: "-x :candid-examples:build -Pgroups=mock" + additional-release-flags: "-x :candid-examples:build -Pgroups=mock" + additional-publish-flags: "-x :candid-examples:build -Pgroups=mock" diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 51edeec..2c642ac 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -12,4 +12,4 @@ jobs: uses: ballerina-platform/ballerina-standard-library/.github/workflows/trivy-scan-template.yml@main secrets: inherit with: - additional-build-flags: "-x test -x :candid-examples:build" + additional-build-flags: "-x :candid-examples:build -Pgroups=mock" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index f41d000..443e99a 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -299,6 +299,18 @@ modules = [ {org = "ballerina", packageName = "url", moduleName = "url"} ] +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + [[package]] org = "ballerinax" name = "candid" @@ -308,12 +320,14 @@ dependencies = [ {org = "ballerina", name = "log"}, {org = "ballerina", name = "os"}, {org = "ballerina", name = "test"}, - {org = "ballerina", name = "url"} + {org = "ballerina", name = "url"}, + {org = "ballerinai", name = "observe"} ] modules = [ {org = "ballerinax", packageName = "candid", moduleName = "candid"}, {org = "ballerinax", packageName = "candid", moduleName = "candid.charitycheckpdf"}, {org = "ballerinax", packageName = "candid", moduleName = "candid.essentials"}, + {org = "ballerinax", packageName = "candid", moduleName = "candid.mock"}, {org = "ballerinax", packageName = "candid", moduleName = "candid.premier"} ] diff --git a/ballerina/modules/charitycheckpdf/client.bal b/ballerina/modules/charitycheckpdf/client.bal index a556aae..8c7a83e 100644 --- a/ballerina/modules/charitycheckpdf/client.bal +++ b/ballerina/modules/charitycheckpdf/client.bal @@ -1,3 +1,6 @@ +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. + // Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, diff --git a/ballerina/modules/charitycheckpdf/tests/test.bal b/ballerina/modules/charitycheckpdf/tests/test.bal index fc217e4..13cd38b 100644 --- a/ballerina/modules/charitycheckpdf/tests/test.bal +++ b/ballerina/modules/charitycheckpdf/tests/test.bal @@ -26,9 +26,20 @@ const EIN = "13-1837418"; ApiKeysConfig apiKeyConfig = { subscriptionKey: apiKey }; -Client charityCheckPDF = check new Client(apiKeyConfig, serviceUrl = "https://apidata.guidestar.org/charitycheckpdf"); -@test:Config +Client charityCheckPDF = test:mock(Client); + +@test:BeforeGroups { + value: ["candid"] +} +function initializeClientsForCandidServer() returns error? { + log:printInfo("Initializing client for Candid server"); + charityCheckPDF = check new (apiKeyConfig, serviceUrl = "https://apidata.guidestar.org/charitycheckpdf"); +} + +@test:Config { + groups: ["candid"] +} function testCharitycheckpdf() returns error? { log:printInfo("charityCheckPDF -> testCharitycheckpdf()"); http:Response result = check charityCheckPDF->/v1/pdf/[EIN]; diff --git a/ballerina/modules/charitycheckpdf/tests/test_w_mock_server.bal b/ballerina/modules/charitycheckpdf/tests/test_w_mock_server.bal new file mode 100644 index 0000000..2c955f6 --- /dev/null +++ b/ballerina/modules/charitycheckpdf/tests/test_w_mock_server.bal @@ -0,0 +1,47 @@ +// 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 candid.mock as _; + +import ballerina/log; +import ballerina/http; +import ballerina/test; + +const EIN = "13-1837418"; + +Client charityCheckPDFForMockServer = test:mock(Client); + +@test:BeforeGroups { + value: ["mock"] +} +function initializeClientsForMockServer() returns error? { + log:printInfo("Initializing client for mock server"); + charityCheckPDF = check new ( + apiKeyConfig = { + subscriptionKey: "6006e88b7fc2e0c31fbcb744cca10cafa280341758cd1db45fc1b29b05305dc0" + }, + serviceUrl = "http://localhost:9090/charitycheckpdf" + ); +} + +@test:Config { + groups: ["mock"] +} +function testCharitycheckpdfMock() returns error? { + log:printInfo("charityCheckPDFForMockServer -> testCharitycheckpdfMock()"); + http:Response result = check charityCheckPDF->/v1/pdf/[EIN]; + test:assertEquals(result.getContentType(), "application/pdf"); +} diff --git a/ballerina/modules/charitycheckpdf/types.bal b/ballerina/modules/charitycheckpdf/types.bal index 6fc0f3a..6eee003 100644 --- a/ballerina/modules/charitycheckpdf/types.bal +++ b/ballerina/modules/charitycheckpdf/types.bal @@ -1,3 +1,6 @@ +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. + // Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, diff --git a/ballerina/modules/charitycheckpdf/utils.bal b/ballerina/modules/charitycheckpdf/utils.bal index 017d12b..9812970 100644 --- a/ballerina/modules/charitycheckpdf/utils.bal +++ b/ballerina/modules/charitycheckpdf/utils.bal @@ -1,3 +1,6 @@ +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. + // Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, diff --git a/ballerina/modules/essentials/tests/test.bal b/ballerina/modules/essentials/tests/test.bal index 9a6d3b9..12cdcff 100644 --- a/ballerina/modules/essentials/tests/test.bal +++ b/ballerina/modules/essentials/tests/test.bal @@ -27,9 +27,20 @@ const KEY_OR_VALUE = "C00"; ApiKeysConfig apiKeyConfig = { subscriptionKey: apiKey }; -Client essentials = check new Client(apiKeyConfig, serviceUrl = "https://api.candid.org/essentials"); -@test:Config +Client essentials = test:mock(Client); + +@test:BeforeGroups { + value: ["candid"] +} +function initializeClientsForCandidServer() returns error? { + log:printInfo("Initializing client for Candid server"); + essentials = check new (apiKeyConfig, serviceUrl = "https://api.candid.org/essentials"); +} + +@test:Config { + groups: ["candid"] +} function testEssentialsV1() returns error? { log:printInfo("essentials -> testEssentialsV1()"); Query query = { @@ -49,7 +60,9 @@ function testEssentialsV1() returns error? { } } -@test:Config +@test:Config { + groups: ["candid"] +} function testEssentialsV2() returns error? { log:printInfo("essentials -> testEssentialsV2()"); Query query = { @@ -69,7 +82,9 @@ function testEssentialsV2() returns error? { } } -@test:Config +@test:Config { + groups: ["candid"] +} function testEssentialsV3() returns error? { log:printInfo("essentials -> testEssentialsV3()"); V3Query query = { @@ -84,7 +99,9 @@ function testEssentialsV3() returns error? { } } -@test:Config +@test:Config { + groups: ["candid"] +} function testEssentialsLookup() returns error? { log:printInfo("essentials -> testEssentialsLookup()"); EssentialsLookupResponse result = check essentials->/lookup; @@ -96,7 +113,9 @@ function testEssentialsLookup() returns error? { } } -@test:Config +@test:Config { + groups: ["candid"] +} function testEssentialsLookupFilterName() returns error? { log:printInfo("essentials -> testEssentialsLookupFilterName()"); EssentialsFilteredLookupResponse result = check essentials->/lookup/[FILTER_NAME]; @@ -108,7 +127,9 @@ function testEssentialsLookupFilterName() returns error? { } } -@test:Config +@test:Config { + groups: ["candid"] +} function testEssentialsLookupFilterNameKeyOrValue() returns error? { log:printInfo("essentials -> testEssentialsLookupFilterNameKeyOrValue()"); EssentialsFilteredLookupResponse result = check essentials->/lookup/[FILTER_NAME]/[KEY_OR_VALUE]; diff --git a/ballerina/modules/essentials/tests/test_w_mock_server.bal b/ballerina/modules/essentials/tests/test_w_mock_server.bal new file mode 100644 index 0000000..f75f401 --- /dev/null +++ b/ballerina/modules/essentials/tests/test_w_mock_server.bal @@ -0,0 +1,142 @@ +// 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 candid.mock as _; + +import ballerina/log; +import ballerina/test; + +const SEARCH_TERM = "candid"; +const FILTER_NAME = "ntee_major"; +const KEY_OR_VALUE = "C00"; + +Client essentialsMockServer = test:mock(Client); + +@test:BeforeGroups { + value: ["mock"] +} +function initializeClientsForMockServer() returns error? { + log:printInfo("Initializing client for mock server"); + essentialsMockServer = check new ( + apiKeyConfig = { + subscriptionKey: "6006e88b7fc2e0c31fbcb744cca10cafa280341758cd1db45fc1b29b05305dc0" + }, + serviceUrl = "http://localhost:9090/essentials" + ); +} + +@test:Config { + groups: ["mock"] +} +function testEssentialsV1Mock() returns error? { + log:printInfo("essentialsMockServer -> testEssentialsV1Mock()"); + Query query = { + search_terms: SEARCH_TERM + }; + V1EssentialsResponse result = check essentialsMockServer->/v1.post(query); + V1EssentialsResponse_data? data = result?.data; + if data is V1EssentialsResponse_data { + V1EssentialsResponse_data_hits[]? hits = data?.hits; + if hits is V1EssentialsResponse_data_hits[] { + test:assertEquals(hits.length(), 25); + } else { + test:assertFail(); + } + } else { + test:assertFail(); + } +} + +@test:Config { + groups: ["mock"] +} +function testEssentialsV2Mock() returns error? { + log:printInfo("essentialsMockServer -> testEssentialsV2Mock()"); + Query query = { + search_terms: SEARCH_TERM + }; + V2EssentialsResponse result = check essentialsMockServer->/v2.post(query); + V2EssentialsResponse_data? data = result?.data; + if data is V2EssentialsResponse_data { + V2EssentialsResponse_data_hits[]? hits = data?.hits; + if hits is V2EssentialsResponse_data_hits[] { + test:assertEquals(hits.length(), 25); + } else { + test:assertFail(); + } + } else { + test:assertFail(); + } +} + +@test:Config { + groups: ["mock"] +} +function testEssentialsV3Mock() returns error? { + log:printInfo("essentialsMockServer -> testEssentialsV3Mock()"); + V3Query query = { + search_terms: SEARCH_TERM + }; + V3EssentialsResponse result = check essentialsMockServer->/v3.post(query); + V3EssentialsResponse_hits[]? hits = result?.hits; + if hits is V3EssentialsResponse_hits[] { + test:assertEquals(hits.length(), 25); + } else { + test:assertFail(); + } +} + +@test:Config { + groups: ["mock"] +} +function testEssentialsLookupMock() returns error? { + log:printInfo("essentialsMockServer -> testEssentialsLookupMock()"); + EssentialsLookupResponse result = check essentialsMockServer->/lookup; + string[]? data = result?.data; + if data is string[] { + test:assertTrue(data.some(val => val == FILTER_NAME)); + } else { + test:assertFail(); + } +} + +@test:Config { + groups: ["mock"] +} +function testEssentialsLookupFilterNameMock() returns error? { + log:printInfo("essentialsMockServer -> testEssentialsLookupFilterNameMock()"); + EssentialsFilteredLookupResponse result = check essentialsMockServer->/lookup/[FILTER_NAME]; + EssentialsFilteredLookupResponse_data[]? data = result?.data; + if data is EssentialsFilteredLookupResponse_data[] { + test:assertTrue(data.some(val => val?.'key == KEY_OR_VALUE)); + } else { + test:assertFail(); + } +} + +@test:Config { + groups: ["mock"] +} +function testEssentialsLookupFilterNameKeyOrValueMock() returns error? { + log:printInfo("essentialsMockServer -> testEssentialsLookupFilterNameKeyOrValueMock()"); + EssentialsFilteredLookupResponse result = check essentialsMockServer->/lookup/[FILTER_NAME]/[KEY_OR_VALUE]; + EssentialsFilteredLookupResponse_data[]? data = result?.data; + if data is EssentialsFilteredLookupResponse_data[] { + test:assertTrue(data.some(val => val?.'key == KEY_OR_VALUE)); + } else { + test:assertFail(); + } +} diff --git a/ballerina/modules/mock/openapi_service.bal b/ballerina/modules/mock/openapi_service.bal new file mode 100644 index 0000000..87462c1 --- /dev/null +++ b/ballerina/modules/mock/openapi_service.bal @@ -0,0 +1,176 @@ +// 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; + +listener http:Listener candidEP = new (9090, config = {host: "localhost"}); + +// CharityCheckPDF API +service /charitycheckpdf on candidEP { + resource function get v1/pdf/[string ein]() returns http:Response|error { + http:Response response = new(); + check response.setContentType("application/pdf"); + return response; + } +} + +// Essentials API +service /essentials on candidEP { + resource function post v1(Query payload) returns EssentialsOkayResponse { + return { + data: { + hits: [ + {organization_id: "0"}, + {organization_id: "1"}, + {organization_id: "2"}, + {organization_id: "3"}, + {organization_id: "4"}, + {organization_id: "5"}, + {organization_id: "6"}, + {organization_id: "7"}, + {organization_id: "8"}, + {organization_id: "9"}, + {organization_id: "10"}, + {organization_id: "11"}, + {organization_id: "12"}, + {organization_id: "13"}, + {organization_id: "14"}, + {organization_id: "15"}, + {organization_id: "16"}, + {organization_id: "17"}, + {organization_id: "18"}, + {organization_id: "19"}, + {organization_id: "20"}, + {organization_id: "21"}, + {organization_id: "22"}, + {organization_id: "23"}, + {organization_id: "24"} + ] + } + }; + } + + resource function post v2(Query payload) returns EssentialsOkayResponse { + return { + data: { + hits: [ + {organization_id: "0"}, + {organization_id: "1"}, + {organization_id: "2"}, + {organization_id: "3"}, + {organization_id: "4"}, + {organization_id: "5"}, + {organization_id: "6"}, + {organization_id: "7"}, + {organization_id: "8"}, + {organization_id: "9"}, + {organization_id: "10"}, + {organization_id: "11"}, + {organization_id: "12"}, + {organization_id: "13"}, + {organization_id: "14"}, + {organization_id: "15"}, + {organization_id: "16"}, + {organization_id: "17"}, + {organization_id: "18"}, + {organization_id: "19"}, + {organization_id: "20"}, + {organization_id: "21"}, + {organization_id: "22"}, + {organization_id: "23"}, + {organization_id: "24"} + ] + } + }; + } + + resource function post v3(Query payload) returns V3EssentialsOkayResponse { + return { + hits: [ + {organization_id: "0"}, + {organization_id: "1"}, + {organization_id: "2"}, + {organization_id: "3"}, + {organization_id: "4"}, + {organization_id: "5"}, + {organization_id: "6"}, + {organization_id: "7"}, + {organization_id: "8"}, + {organization_id: "9"}, + {organization_id: "10"}, + {organization_id: "11"}, + {organization_id: "12"}, + {organization_id: "13"}, + {organization_id: "14"}, + {organization_id: "15"}, + {organization_id: "16"}, + {organization_id: "17"}, + {organization_id: "18"}, + {organization_id: "19"}, + {organization_id: "20"}, + {organization_id: "21"}, + {organization_id: "22"}, + {organization_id: "23"}, + {organization_id: "24"} + ] + }; + } + + resource function get lookup() returns EssentialsLookupOkayResponse { + return { + data: ["ntee_major", "ntee_minor"] + }; + } + + resource function get lookup/[string filter_name]() returns EssentialsFilteredLookupOkayResponse { + return { + data: [ + {'key: "C00"}] + }; + } + + resource function get lookup/[string filter_name]/[string key_or_value]() returns EssentialsFilteredLookupOkayResponse { + return { + data: [ + {'key: "C00"}] + }; + } +} + +// Premier API +service /premier on candidEP { + resource function get v1/propdf/[string ein]() returns http:Response|error { + http:Response response = new(); + check response.setContentType("application/pdf"); + return response; + } + + resource function get v1/ftapdf/[string ein]() returns http:Response|error { + http:Response response = new(); + check response.setContentType("application/pdf"); + return response; + } + + resource function get v3/[string ein]() returns PublicProfileOkayResponse { + return { + data: { + summary: { + ein: "13-1837418" + } + } + }; + } +} diff --git a/ballerina/modules/mock/types.bal b/ballerina/modules/mock/types.bal new file mode 100644 index 0000000..0c3ca28 --- /dev/null +++ b/ballerina/modules/mock/types.bal @@ -0,0 +1,61 @@ +// 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. + +// Essentials Mock Service Related Types +type Query record { + string? search_terms?; +}; + +type EssentialsOkayResponse record { + EssentialsResponse_data? data?; +}; + +type EssentialsResponse_data record { + EssentialsResponse_data_hits[]? hits?; +}; + +type EssentialsResponse_data_hits record { + string? organization_id?; +}; + +type V3EssentialsOkayResponse record { + EssentialsResponse_data_hits[]? hits?; +}; + +type EssentialsLookupOkayResponse record { + string[]? data?; +}; + +type EssentialsFilteredLookupOkayResponse record { + EssentialsFilteredLookupResponse_data[]? data?; +}; + +type EssentialsFilteredLookupResponse_data record { + string? 'key?; +}; + +// Premier Mock Service Related Types +type PublicProfileOkayResponse record { + V3PublicProfile_data? data?; +}; + +type V3PublicProfile_data record { + Summary3? summary?; +}; + +type Summary3 record { + string? ein?; +}; diff --git a/ballerina/modules/premier/tests/test.bal b/ballerina/modules/premier/tests/test.bal index 45b210e..45f1447 100644 --- a/ballerina/modules/premier/tests/test.bal +++ b/ballerina/modules/premier/tests/test.bal @@ -26,23 +26,38 @@ const EIN = "13-1837418"; ApiKeysConfig apiKeyConfig = { subscriptionKey: apiKey }; -Client premier = check new Client(apiKeyConfig, serviceUrl = "https://api.candid.org/premier"); -@test:Config +Client premier = test:mock(Client); + +@test:BeforeGroups { + value: ["candid"] +} +function initializeClientsForCandidServer() returns error? { + log:printInfo("Initializing client for Candid server"); + premier = check new (apiKeyConfig, serviceUrl = "https://api.candid.org/premier"); +} + +@test:Config { + groups: ["candid"] +} function testPremierV1Propdf() returns error? { log:printInfo("premier -> testPremierV1Propdf()"); http:Response result = check premier->/v1/propdf/[EIN]; test:assertEquals(result.getContentType(), "application/pdf"); } -@test:Config +@test:Config { + groups: ["candid"] +} function testPremierV1ftapdf() returns error? { log:printInfo("premier -> testPremierV1ftapdf()"); http:Response result = check premier->/v1/ftapdf/[EIN]; test:assertEquals(result.getContentType(), "application/pdf"); } -@test:Config +@test:Config { + groups: ["candid"] +} function testPremierV3() returns error? { log:printInfo("premier -> testPremierV3()"); V3PublicProfile result = check premier->/v3/[EIN]; diff --git a/ballerina/modules/premier/tests/test_w_mock_server.bal b/ballerina/modules/premier/tests/test_w_mock_server.bal new file mode 100644 index 0000000..42bad63 --- /dev/null +++ b/ballerina/modules/premier/tests/test_w_mock_server.bal @@ -0,0 +1,75 @@ +// 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 candid.mock as _; + +import ballerina/log; +import ballerina/http; +import ballerina/test; + +const EIN = "13-1837418"; + +Client premierMockServer = test:mock(Client); + +@test:BeforeGroups { + value: ["mock"] +} +function initializeClientsForMockServer() returns error? { + log:printInfo("Initializing client for mock server"); + premierMockServer = check new ( + apiKeyConfig = { + subscriptionKey: "6006e88b7fc2e0c31fbcb744cca10cafa280341758cd1db45fc1b29b05305dc0" + }, + serviceUrl = "http://localhost:9090/premier" + ); +} + +@test:Config { + groups: ["mock"] +} +function testPremierV1PropdfMock() returns error? { + log:printInfo("premierMockServer -> testPremierV1PropdfMock()"); + http:Response result = check premierMockServer->/v1/propdf/[EIN]; + test:assertEquals(result.getContentType(), "application/pdf"); +} + +@test:Config { + groups: ["mock"] +} +function testPremierV1ftapdfMock() returns error? { + log:printInfo("premierMockServer -> testPremierV1ftapdfMock()"); + http:Response result = check premierMockServer->/v1/ftapdf/[EIN]; + test:assertEquals(result.getContentType(), "application/pdf"); +} + +@test:Config { + groups: ["mock"] +} +function testPremierV3Mock() returns error? { + log:printInfo("premierMockServer -> testPremierV3Mock()"); + V3PublicProfile result = check premierMockServer->/v3/[EIN]; + V3PublicProfile_data? data = result?.data; + if data is V3PublicProfile_data { + Summary3? summary = data?.summary; + if summary is Summary3 { + test:assertEquals(summary?.ein, EIN); + } else { + test:assertFail(); + } + } else { + test:assertFail(); + } +}