Skip to content

Commit

Permalink
1.21 release (#132)
Browse files Browse the repository at this point in the history
* Cscttv 2132 (#24)

* Add openshift config for api devel.

* Modify Docker build path.

* Add openshift config for identityserver devel.

* Test permission change in container app folder.

* Modify run time permissions

* Change SDK version in Identityserver build.

* Change build branch to devel. Change Rahti container image path.

* Remove researchfi prefix from Openshift config.

* Add README for api application.

* Upgrade Nuget packages.

* CSCTTV-2132_2 (#25)

* Modify Openshift template and Dockerfile for Identityserver.

* Modify image pull path.

* Modify image pull path.

* Add README in Identityserver project.

* Update README.md

* Update README.md

* Modify Git source branch and container path in Identityserver template.

* Remove Identityserver tempkey.jwk and add it in gitignore.

* Change app folder permission in Identityserver container.

* Do not initialize ElasticsearchService without required configuration values.

* CSCTTV-2123 Elasticsearch sync (#26)

* First draft of how data can be synced in Elasticsearch.

* Elasticsearch connection parameters from configuration.

* Add data types for Elasticsearch.

* Add more data in Elasticsearch person index.

* Delete tempkey.jwk

* Add Elasticsearch environment variables in api README. Add identityserver's tempkey.jwk in .gitignore.

* Simplify Elasticsearch service and change it to singleton instead of scoped service.

* Use connection resiliency with SQL Server provider.

* Always set field Modified to current timestamp when creating a new entry in database.

* Add more logging in ElasticsearchService.

* Improve handling of NEST error messages when adding or deleting entry in Elasticsearch.

* Remove unused controller.

* Use raw SQL query for getting DimUserProfile based on ORCID Id in DimPid. Clean up startup.cs dependencies.

* Use raw SQL query when retrieving ORCID registered data source from DimRegisteredDataSource.

* Upgrade Nuget packages in api project.

* Code clean up, remove repetitive code.

* Use raw sql when updating FactFieldValue table. Change created and modified timestamp to DateTime.UtcNow instead of DateTime.Now. Add namespace api.models.ProfileEditor.

* Add unit tests for TtvSqlService.
In TtvSqlService add own function for getting FactFieldValues FK column name based on field identifier.

* Simplify queries which get data for profile editor and elasticsearch index.

* When getting data for profile editor, get only those DimFieldDisplaySettings, which have at least one related FactFieldValue.

* Update Elasticsearch in a background task. (#27)

* When profile is created, include ORCID name automatically in profile.

* In ORCID controller remove unnecessary retrieval of DimKnownPerson entity.

* Remove multiple publicationIds from profile in the same api query.

* Remove cached profiledata when publications are added or removed.

* Use field identifier 550 with ORCID publications.
When userprofile is deleted, remove cached profiledata and remove Elasticsearch entry in background task.

* Enable split SQL query behaviour globally. Fix bug in ORCID publication handling.

* Call SaveChangesAsync only once when ORCID data is imported.

* Call SaveChangesAsync only once when adding demo data into user profile.

* Modify Identityserver Javascript client configuration handling.

* Add cooperation selection api (demo) (#28)

* Add draft version of cooperation selection api.

* Modify cooperation choice text content.

* Add Swagger documentation. (#29)

* Add Swagger documentation.

* Simplify cooperationdemo api. Swagger documentation improvements.

* Comment out Swagger, because the configuration does not work in Docker build.

* Enable Swagger in development environment

* Modify xml documentation generation. Modify environment handling in startup.

* Add LanguageService. (#30)

* Language service and name translation improvements.

* Add DimUserChoice in Ttv model. Add DimUserChoice handling in CooperationChoicesController. (#31)

* Compress api responses.

* Profile API for adding and removing funding decisions. (#32)

* Add controller and models for DimFundingDecision handling.

* Add funding decision handling in user profile.

* Add funding decision in demo data.

* Add DimFundingDecision demo data.

* Modify demo data. Modify FundingDecisionController functionality.

* Simplify addFungingDecision API response.

* CSCTTV-1703 research dataset handling in profile API (#33)

* Add controller and models for DimResearchDataset handling.

* Add relation between DimResearchDataset and FactFieldValues. Modify FundingDecisionController to use updated Ttv data model.

* Add part of research dataset demo data.

* Modify research dataset demo data handling. Modify demo data deletion.

* Modify research dataset structure in profile data API response.

* Comment out profile data query items.

* Include ORCID ID in demodata source id field.

* Modify research dataset demo data.

* Fix bug in research dataset demodata creation. Modify user profile deletion.

* Add funding decision and research dataset column names in TtvSqlService.

* Optimize user profile  and related data deletion.

* Add department name in affiliation. Demo implementation, not production ready. (#34)

* Improve handling of null values in name translation.

* Restore previous functionality in user profile deletion.

* Change funding decision handling to use projectId instead of funderProjectNumber. (#35)

* Fix typo in funding decision property name.

* Add OpenShift templates for demo version.

* Change start and end date property names in funding decision item.

* Add property datasetCreated in research dataset item.

* Change demo version openshift build config git branch.

* Comment out querying DimIdentifierlessData because of data model mismatch.

* Add user profile id in cooperation item query.

* Return API response immediately when there are no items to add or remove.

* Add debug controller for getting debug data and statistics.

* Sql model update 2021 12 (#37)

* Remove log print of user profile existence check.

* Add api response compression.

* Ttv model update according to latest SQL database structure. Major change to handling of registered data source, work in progress.

* Version which builds without errors. Elasticsearch synchronization and debug controller have some parts of code commented out.

* Modify user profile creation, adding demo data and adding ORCID data.

* Modify registered data source handling in profile data load.

* Fix bug, which prevents deleting DimFieldDisplaySettings related to user profile.

* Move profile editor data retrieval code into UserProfileService.

* Modify profile data handling in Elasticsearch synchronization.

* Modify SourceId field handling. Fix ORCID import bugs in DimName and DimResearcherDescription.

* Handle missing name element when parsing ORCID record.

* Upgrade Nuget packages. Modify DemoDataService.

* Filter query to get only ORCID related entities. Remove manual adjustment of EntityState.

* Get list of available FieldIdentifiers from UserProfileService. Add unit test to validate FieldIdentifier list content.

* Add type code in publication and ORCID publication. (#38)

* Fix bug where fromCache property was not set in ApiResponseProfileDataGet.

* Take DOI from DimPublication.Doi instead of DimPublication.DoiHandle

* Set ORCID member api scopes. Store and update user's ORCID access token on ORCID login. (#39)

* Store ORCID tokens from Keycloak external IDP token endpoint. Add TokenService. (#40)

* Add missing dependency injection in TokenService

* Add Keycloak account linking. Add named http clients. Modify configuration parameters. (#41)

* Require specific scope and orcid claim in controller authorization policy. (#42)

* Add DuplicateHandlerService (#43)

* Add DupplicateHandlerService and unit tests. Add temporary models and controller for testing purposes.

* Modify DuplicateHandlerService unit tests

* Logout and delete Keycloak user when user profile is deleted. (#44)

* EF model update. Registered data source handling changes. (#45)

* EF model scaffolded from test database on 5.5.2022.

* Modify ORCID and Tiedejatutkimus.fi data source handling.

* Add missing model files.

* Store ORCID and TTV registered data source and organization values into a singleton service on startup. (#46)

* Fixes suggested by Visual Studio code analyzer (#47)

* Remove IdentityServer (#48)

* Affiliation organization and department name handling in ORCID import (#49)

* Add OrcidImportService. Move logic from controller to service. Modify Orcid json parser unit tests.

* Add OrganizationHandlerService. Modify organization name handling in ORCID import and profile data deletion.

* Modify affiliation related organization search in ORCID import. Modify affiliation deletion.

* Modify affiliation department name handling.

* Modify ORCID disambiguation source mapping, add unit test.

* Move logic from controllers to services. (#50)

* Improvements in background Elasticsearch index update (#51)

* Queue background tasks according to Microsoft documentation.

* Check if Elasticsearch sync feature is enabled before adding items to task queue.

* Update NuGet packages (#52)

* Add ” (test)” in temporary organization names

* Update TTV model. Add DueDateDueTime into DimCallProgramme

* Update TTV model change. PK in BrGrantedPermission

* Remove demo data related code from user profile deletion.

* Do not delete DimResearchDataset on profile deletion

* Migrate from ASP.NET Core 5.0 to 6.0 (#53)

* Add sharing API for profile editor (#54)

* Add SharingController and SharingService

* Profile sharing related database queries on application startup.

* DimReferenceData handling when setting user profile default permissions.

* Add SharingController and draft data

* Add API endpoints for getting available sharing permissions and purposes. Language service bugfix.

* Rename sharing purpose related model.

* Add endpoints for listing, adding and removing of share permissions.

* Change OKM organization id (#55)

* Add Openshift template for Artifactory build. Remove unused templates. (#56)

* Startup.cs code clean up.

* Use interfaces in dependecy injection. (#57)

* Add Serilog for logging. (#58)

* Add GitHub codeql (#61)

* Add GitHub action CodeQL.

* Modify CodeQL GitHub action

* Check only csharp in GitHub action CodeQL.

* Modify log format.

* Modify log message content. (#62)

* CSCTTV-2724 Improvements in profile creation (#63)

* Improved TTV database search when creating user profile.

* Add research activity search on profile creation.

* CSCTTV-2720 Improve testability (#64)

* Add debug methods to create and delete a user profile to any ORCID ID in dim_pid.

* Get ORCID record from public API when a specific flag is set in access token.

* Fix bug in parsing of ORCID record education element

* Import from ORCID only one entry of the same publication. (#65)

* Enable database command logging

* Use TagWith in queries to make debug log more readable.

* Optimized profile data query using Dapper (#66)

* Add Dapper. Get profiledata using raw sql.

* Profile data person section query converted to raw sql.

* Partially completed version of new profile data query using Dapper.

* Add dim_education handling in new profile data query.

* Add dim_publication and dim_orcid_publication handling in new profile data query.

* Moved profile data SQL string into TtvSqlService. Use new profile data query in Elasticsearch index update.

* Add missing ITtvSqlService.cs, which was dropped by malfunctioning IDE.

* Removed old code from UserProfileService

* Profile data deletion using Dapper (#67)

* Initial code for deleting user profile using Dapper. Modify unit tests. Upgrade packages.

* First working version of profile data deletion using Dapper.

* Fix bug in deleting ORCID put codes from dim_pid. Add unit tests SQL statement creation.

* Removed commented code.

* Profile data response using new data structure. (#68)

* New data structure in profile data response

* Profile data personal section converted to new data structure.

* Profile data activity section converted to new data structure.

* Remove commented code and temporary modification in controller.

* Modify DuplicateHandlerService unit tests.

* Fix bug in Swagger documentation. Set controller route names explicitly.

* Optimized profile deletion (#69)

* Delete multiple IDs from dim_pid and dim_orcid_publication in the same SQL statement.

* Delete multiple rows in one SQL statement using WHERE id IN condition

* Update TTvSqlService unit tests.

* Update field identifiers, unit tests and dependencies.

* Use Automapper to create Elasticsearch data object from profile editor data object. (#70)

* Limit profiledata in Elastic index to published items only. (#71)

* Add property activitiesAndRewards into profiledata. Add property researchDatasets into Elasticsearch profiledata. (#72)

* Update SQL query for dim_research_activity. Update profiledata contents. (#73)

* Funding decision handling in SQL query and API response (#74)

* Research dataset handling in SQL query and API response (#75)

* Fix missing itemMeta in profile editor data.

* Add API endpoint accountdelete for removing Keycloak user. (#76)

* Cscttv 2799 hide national identification number (#77)

* Add own folder structure for Keycloak related files.

* Modify Java project naming. Add readme.

* Modify Keycloak Dockerfile

* Add custom Keycloak extension into build_dependencies folder.

* Add OpenShift template for Keycloak devel. Modify Keycloak Dockerfile. (#78)

* Rename Keycloak OpenShift template entries

* Add Keycloak version number 19 in OpenShift template to avoid collision with old installation.

* Fix bug in Keycloak custom provider URL.

* Comment out automatic certificate generation in Keycloak container.

* Add list of unique data sources in profile data and Elasticsearch index. (#79)

* Add SectorId in organization data. (#80)

* Add property primaryValue in Elasticsearch data. (#81)

* Remove obsolete API code. Organize models. Update dependencies. (#82)

* Remove DemoDataService

* Reduce EntityFramework database log level.

* Remove duplicate field PrimaryValue from elasticsearch model. (#83)

* Remove duplicate PrimaryValue fields from Elasticsearch models. (#84)

* Rename controller and route for profiledata. (#85)

* Add OpenShift templates for QA and production. (#86)

* Fix bug where duplicate dates are inserted during ORCID import. (#88)

* Fix bug in cache key naming. (#89)

* Set production CORS allowed origins. (#90)

* Change ORCID and TTV data source organization names. Add UtilityService unit tests. (#91)

* Comment out sharing feature related database query. (#92)

* Add QA domains in allowed origins for production. (#93)

* Add affiliation organization sector data. (#94)

* Check that Elasticsearch index exists. Add index mapping. (#95)

* Check that Elasticsearch index exists. Add Elasticsearch mapping for sector in afiiliation.

* Fix bug in ElasticsearchService constructor.

* Modify DimKnownPerson handling in profile creation phase. (#96)

* Add role code and name in research activity. (#97)

* Allow all data sources when adding TTV data based on known person dim_names (#98)

* Revert allowing all data sources (#99)

* Add profile settings controller and possibility to hide profile from portal. (#100)

* Improved TTV data collection (#101)

* New version of TTV data collection

* Fix incorrect DimFieldDisplaySettings reference in TTV data collection.

* Add research activity type handling in profile editor data. (#102)

* Name and other name handling when collecting TTV data. (#103)

* Modify Elasticsearch person index mapping (#104)

* Change how funding decisions are searched during profile creation. (#105)

* Web link handling in TTV data collection (#106)

* Fix bug where PATCH fails on research activity. (#107)

* Filter dim_names based on dim_registered_data_source.name (#108)

* Trigger Elasticsearch person index update from controllers (#110)

* Handle multi level organization relationship in affiliation organization name (#112)

* Prevent duplicates and -1 rows in fact_contribution SQL query. (#113)

* Add fields in profile editor and elasticsearch publication. (#114)

* Add field authorsText to publication

* Add fields JournalName, ConferenceName and ParentPublication name into publication.

* ORCID import improved checking and simplified query. (#115)

* Ignore possible duplicates when adding items to profile. (#116)

* Make sure publication year is null instead of 0. (#117)

* Entity framework model update. Scaffolded from database. (#118)

* Add ORCID webhook handling (#119)

* Add WebhookController. Add backgroung task for updating ORCID data.

* ORCID webhook registration

* Improve OrcidApiService unit tests.

* Add ORCID webhook registration and unregistration API calls.

* Modify configuration parameter names for ORCID webhook. Improve OrcidApiService unit tests.

* Upgrade NuGet packages. (#120)

* Add AdminController. Add admin commands for ORCID webhooks. Add comments. (#121)

* Add admin command to update user profile in Elasticsearch (#122)

* TTV model update 28.12.2022 (#123)

* Add GitHub action: build and unit test (#124)

* Ttv model update 30.12.2022 (#125)

* Ttv model update 3.1.2023 (#126)

* Cscttv 2075 opensearch logging configuration (#127)

* Add custom NuGet source for local packages. Add custom OpenSearch sink for Serilog.

* Structured log messages.

* Change log messages to use structured format.

* Structured log messages in services.

* Add log message in AccountLinkController

* Handle NuGet custom files in Docker build

* Modify Dockerfile

* Modify Dockerfile

* Modify Dockerfile

* Modify Dockerfile

* Change log model folder name to avoid gitignore

* Modify Serilog config in appsettings.json

* TTV model update 10.1.2023 (#128)

* TTV model update 10.1.2023

* Add missing models

* Store log user information in a variable in admin controller. (#129)

* Define outputTemplate for Serilog console sink. (#130)

* Use monthly indexes in  OpenSearch logging (#131)

* Fix error from merge conflict.
  • Loading branch information
sarkikos authored Jan 30, 2023
1 parent 384d674 commit d8480fe
Show file tree
Hide file tree
Showing 143 changed files with 4,421 additions and 1,414 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
pull_request:
branches:
- "devel"
- "qa"
- "master"
- "main"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
working-directory: aspnetcore/
- name: Build
run: dotnet build --no-restore
working-directory: aspnetcore/
- name: Test
run: dotnet test --no-build --verbosity normal
working-directory: aspnetcore/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ PublishScripts/
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# except custom packages
!**/custom_nuget/*

# Microsoft Azure Build Output
csx/
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions aspnetcore/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Local" value="custom_nuget/" />
</packageSources>
</configuration>
2 changes: 2 additions & 0 deletions aspnetcore/openshift/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY aspnetcore/custom_nuget/ /app/custom_nuget
COPY aspnetcore/nuget.config ./
COPY aspnetcore/src/api/api.csproj ./
RUN dotnet restore
# Copy everything else and build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2461,17 +2461,7 @@
},
"url": null,
"type": "journal-article C",
"publication-date": {
"year": {
"value": "2012"
},
"month": {
"value": "10"
},
"day": {
"value": "01"
}
},
"publication-date": null,
"journal-title": {
"value": "Learned Publishing"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ public void addPublicationToProfileEditorData_020()
{
Id = 1,
RegisteredDataSource = "Virta",
Organization = new Organization() {}
Organization = new Organization() { }
};
ProfileEditorSource profileEditorSourceOrcid = new()
{
Id = 2,
RegisteredDataSource = "ORCID",
Organization = new Organization() {}
Organization = new Organization() { }
};

// Create ProfileDataRaw for Virta publication 1
Expand Down Expand Up @@ -351,5 +351,21 @@ public void addPublicationToProfileEditorData_020()
// Check that publication list contains two publications
Assert.Equal(2, publications3.Count);
}


[Fact(DisplayName = "TestPublicationYearHandling")]
public void testPublicationYearHandling()
{
DuplicateHandlerService duplicateHandlerService = new();

// Valid publication year
Assert.Equal<int?>(2022, duplicateHandlerService.HandlePublicationYear(2022));
// Publication year 0
Assert.Null(duplicateHandlerService.HandlePublicationYear(0));
// Publication year negative
Assert.Null(duplicateHandlerService.HandlePublicationYear(-1));
// Publication year null
Assert.Null(duplicateHandlerService.HandlePublicationYear(null));
}
}
}
190 changes: 190 additions & 0 deletions aspnetcore/src/api.Tests/Services_Tests/OrcidApiServicetest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
using Xunit;
using Moq;
using api.Services;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using static System.Net.WebRequestMethods;
using System.Security.Cryptography;
using System.Collections;

namespace api.Tests
{
[Collection("ORCID api service tests")]
public class OrcidApiServiceTests
{
/*
* Helper method for setting up IConfiguration
*/
public IConfiguration CreateTestConfiguration()
{
Dictionary<string, string> inMemorySettings = new Dictionary<string, string> {
{ "SERVICEURL", "https://mydata-api.service.example.fi"},
{ "ORCID:WEBHOOK:ENABLED", "true"},
{ "ORCID:WEBHOOK:API", "https://api.sandbox.orcid.org/"},
{ "ORCID:WEBHOOK:ACCESSTOKEN", "fake20e90b06-0384f05d-3ffc9bd9-31ab06ff" }
};
IConfiguration testConfiguration = new ConfigurationBuilder()
.AddInMemoryCollection(inMemorySettings)
.Build();
return testConfiguration;
}

/*
* Create test data for unit test IsOrcidWebhookEnabled_ReturnsIsOrcidWebhookFeatureEnabled
*/
public class IsOrcidWebhookEnabledTestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
// Valid configuration
yield return new object[] {
new Dictionary<string, string> {
{ "SERVICEURL", "https://mydata-api.service.example.fi"},
{ "ORCID:WEBHOOK:ENABLED", "true"},
{ "ORCID:WEBHOOK:API", "https://api.sandbox.orcid.org/"},
{ "ORCID:WEBHOOK:ACCESSTOKEN", "fake20e90b06-0384f05d-3ffc9bd9-31ab06ff" }
},
true
};
// Required configuration completely missing
yield return new object[] {
new Dictionary<string, string> {},
false
};
// SERVICEURL is not defined
yield return new object[] {
new Dictionary<string, string> {
{ "ORCID:WEBHOOK:ENABLED", "false"},
{ "ORCID:WEBHOOK:API", "https://api.sandbox.orcid.org/"},
{ "ORCID:WEBHOOK:ACCESSTOKEN", "fake20e90b06-0384f05d-3ffc9bd9-31ab06ff" }
},
false
};
// ORCID:WEBHOOK:ENABLED = false
yield return new object[] {
new Dictionary<string, string> {
{ "SERVICEURL", "https://mydata-api.service.example.fi"},
{ "ORCID:WEBHOOK:ENABLED", "false"},
{ "ORCID:WEBHOOK:API", "https://api.sandbox.orcid.org/"},
{ "ORCID:WEBHOOK:ACCESSTOKEN", "fake20e90b06-0384f05d-3ffc9bd9-31ab06ff" }
},
false
};
// ORCID:WEBHOOK:ENABLED is not defined
yield return new object[] {
new Dictionary<string, string> {
{ "SERVICEURL", "https://mydata-api.service.example.fi"},
{ "ORCID:WEBHOOK:API", "https://api.sandbox.orcid.org/"},
{ "ORCID:WEBHOOK:ACCESSTOKEN", "fake20e90b06-0384f05d-3ffc9bd9-31ab06ff" }
},
false
};
// ORCID:WEBHOOK:API is not defined
yield return new object[] {
new Dictionary<string, string> {
{ "SERVICEURL", "https://mydata-api.service.example.fi"},
{ "ORCID:WEBHOOK:ENABLED", "true"},
{ "ORCID:WEBHOOK:ACCESSTOKEN", "fake20e90b06-0384f05d-3ffc9bd9-31ab06ff" }
},
false
};
// ORCID:WEBHOOK:ACCESSTOKEN is not defined
yield return new object[] {
new Dictionary<string, string> {
{ "SERVICEURL", "https://mydata-api.service.example.fi"},
{ "ORCID:WEBHOOK:ENABLED", "true"},
{ "ORCID:WEBHOOK:API", "https://api.sandbox.orcid.org/"}
},
false
};
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

[Fact(DisplayName = "Get correct path for ORCID record")]
public void GetOrcidRecordPath_OrcidId_ReturnsCorrectPath()
{
// Arrange
OrcidApiService orcidApiService = new OrcidApiService();
// Act
string actualOrcidRecordPath = orcidApiService.GetOrcidRecordPath("1234-5678-8765-4321");
// Assert
Assert.Equal("1234-5678-8765-4321/record", actualOrcidRecordPath);
}

[Theory(DisplayName = "Check is ORCID webhook feature enabled")]
[ClassData(typeof(IsOrcidWebhookEnabledTestData))]
public void IsOrcidWebhookEnabled_ReturnsIsOrcidWebhookFeatureEnabled(Dictionary<string, string> inMemorySettings, bool expectedResult)
{
// Arrange
IConfiguration testConfiguration = new ConfigurationBuilder()
.AddInMemoryCollection(inMemorySettings)
.Build();
OrcidApiService orcidApiService = new OrcidApiService(testConfiguration);
// Act
bool actualIsOrcidWebhookEnabled = orcidApiService.IsOrcidWebhookEnabled();
// Assert
Assert.Equal(expectedResult, actualIsOrcidWebhookEnabled);
}

[Fact(DisplayName = "Get ORCID webhook callback URI for ORCID ID")]
public void GetOrcidWebhookCallbackUri_OrcidId_ReturnsCorrectCallbackUri()
{
// Arrange
IConfiguration testConfiguration = CreateTestConfiguration();
OrcidApiService orcidApiService = new OrcidApiService(testConfiguration);
// Act
string actualOrcidWebhookCallbackUri = orcidApiService.GetOrcidWebhookCallbackUri(orcidId: "0000-0001-2000-3456");
// Assert
Assert.Equal(
"https://mydata-api.service.example.fi/api/webhook/orcid/0000-0001-2000-3456",
actualOrcidWebhookCallbackUri
);
}

[Fact(DisplayName = "Get URL encoded string")]
public void GetUrlEncodedString_URI_ReturnsUrlEncodedString()
{
// Arrange
OrcidApiService orcidApiService = new OrcidApiService();
// Act
string actualUrlEncodedString =
orcidApiService.GetUrlEncodedString("https://mydata-api.service.example.fi/api/webhook/orcid/0000-0001-2000-3456");
// Assert
Assert.Equal(
"https%3a%2f%2fmydata-api.service.example.fi%2fapi%2fwebhook%2forcid%2f0000-0001-2000-3456",
actualUrlEncodedString
);
}

[Fact(DisplayName = "Get ORCID webhook registration URL for ORCID ID")]
public void GetOrcidWebhookRegistrationUri_OrcidId_ReturnsCorrectRegistrationUri()
{
// Arrange
IConfiguration testConfiguration = CreateTestConfiguration();
OrcidApiService orcidApiService = new OrcidApiService(testConfiguration);
// Act
string actualOrcidWebhookRegistrationUri = orcidApiService.GetOrcidWebhookRegistrationUri("0000-0001-2000-3456");
// Assert
Assert.Equal(
"https://api.sandbox.orcid.org/0000-0001-2000-3456/webhook/https%3a%2f%2fmydata-api.service.example.fi%2fapi%2fwebhook%2forcid%2f0000-0001-2000-3456",
actualOrcidWebhookRegistrationUri
);
}

[Fact(DisplayName = "Get ORCID webhook access token from configuration")]
public void GetOrcidWebhookAccessToken_ReturnsOrcidWebhookAccessTokenFromConfiguration()
{
// Arrange
IConfiguration testConfiguration = CreateTestConfiguration();
OrcidApiService orcidApiService = new OrcidApiService(testConfiguration);
// Act
string actualOrcidWebhookAccessToken = orcidApiService.GetOrcidWebhookAccessToken();
// Assert
Assert.Equal(
"fake20e90b06-0384f05d-3ffc9bd9-31ab06ff",
actualOrcidWebhookAccessToken
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public void TestGetPublications()

Assert.Equal("Another publication", actualPublications[2].PublicationName);
Assert.Equal(new OrcidPutCode(733536).Value, actualPublications[2].PutCode.Value);
Assert.Equal(2012, actualPublications[2].PublicationYear);
Assert.Null(actualPublications[2].PublicationYear);
Assert.Equal("10.1087/20120404", actualPublications[2].Doi);
Assert.Equal("journal-article C", actualPublications[2].Type);
}
Expand Down
24 changes: 23 additions & 1 deletion aspnetcore/src/api.Tests/Services_Tests/TtvSqlServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FactFieldValue GetFactFieldValueForTest()
DimEmailAddrressId = -1,
DimEventId = -1,
DimFieldDisplaySettingsId = -1,
DimFieldOfScienceId = -1,
DimReferencedataFieldOfScienceId = -1,
DimFundingDecisionId = -1,
DimIdentifierlessDataId = -1,
DimKeywordId = -1,
Expand Down Expand Up @@ -167,6 +167,16 @@ public void getFactFieldValuesFKColumnNameFromFieldIdentifier_dim_research_datas
);
}

[Fact(DisplayName = "Get FactFieldValues FK column name - dim_research_activity_id")]
public void getFactFieldValuesFKColumnNameFromFieldIdentifier_dim_research_activity_id()
{
TtvSqlService ttvSqlService = new();
// Research activity
Assert.Equal(
"dim_research_activity_id", ttvSqlService.GetFactFieldValuesFKColumnNameFromFieldIdentifier(Constants.FieldIdentifiers.ACTIVITY_RESEARCH_ACTIVITY)
);
}

[Fact(DisplayName = "Test that list of integers is converted to a comma separated string")]
public void Test_ConvertListOfIntsToCommaSeparatedString()
{
Expand Down Expand Up @@ -497,5 +507,17 @@ public void Test_GetSqlQuery_Delete_DimUserProfile()
string actualSqlString = ttvSqlService.GetSqlQuery_Delete_DimUserProfile(221199);
Assert.Equal(expectedSqlString, actualSqlString);
}

[Fact(DisplayName = "Get SQL query for counting number of published items in userprofile")]
public void GetSqlQuery_Select_CountPublishedItemsInUserprofile()
{
TtvSqlService ttvSqlService = new();
string expectedSqlString = $@"SELECT COUNT(ffv.show) AS 'PublishedCount'
FROM fact_field_values AS ffv
JOIN dim_user_profile AS dup ON ffv.dim_user_profile_id=dup.id
WHERE dup.id=335577 AND ffv.show=1";
string actualSqlString = ttvSqlService.GetSqlQuery_Select_CountPublishedItemsInUserprofile(335577);
Assert.Equal(expectedSqlString, actualSqlString);
}
}
}
30 changes: 30 additions & 0 deletions aspnetcore/src/api.Tests/Services_Tests/UtilityServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Xunit;
using api.Services;

namespace api.Tests
{
[Collection("Utility service tests")]
public class UtilityServiceTests
{
[Fact(DisplayName = "Get correct data source organization name - ORCID")]
public void getCorrectDataSourceOrganizationName_ORCID()
{
var utilityService = new UtilityService();
Assert.Equal("ORCID", utilityService.GetDatasourceOrganizationName_ORCID());
}

[Fact(DisplayName = "Get correct data source organization name - TTV")]
public void getCorrectDataSourceOrganizationName_TTV()
{
var utilityService = new UtilityService();
Assert.Equal("Tiedejatutkimus.fi", utilityService.GetDatasourceOrganizationName_TTV());
}

[Fact(DisplayName = "Get correct organization ID - OKM")]
public void getCorrectOrganizationID_OKM()
{
var utilityService = new UtilityService();
Assert.Equal("02w52zt87", utilityService.GetOrganizationId_OKM());
}
}
}
Loading

0 comments on commit d8480fe

Please sign in to comment.