Skip to content

Commit

Permalink
feat(service): only create org license if license non-null
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdiw committed Mar 18, 2024
1 parent bffe4a9 commit 83a50f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -32,6 +32,13 @@ public Optional<License> getLicenseByOrganizationId(String organizationId) {
return this.licenseCrudService.getOrganizationLicense(organizationId);
}

/**
* Create or update license by organization ID.
* If on create and license is null, no license is saved in the database.
* If on update and license is the same, no license is updated.
* @param organizationId -- organization identifier
* @param license -- license content to be saved
*/
public void createOrUpdateOrganizationLicense(String organizationId, String license) {
this.licenseCrudService.getOrganizationLicense(organizationId)
.ifPresentOrElse(
Expand All @@ -40,7 +47,11 @@ public void createOrUpdateOrganizationLicense(String organizationId, String lice
this.licenseCrudService.updateOrganizationLicense(organizationId, license);
}
},
() -> this.licenseCrudService.createOrganizationLicense(organizationId, license)
() -> {
if (Objects.nonNull(license)) {
this.licenseCrudService.createOrganizationLicense(organizationId, license);
}
}
);
}
}
Expand Up @@ -53,6 +53,16 @@ void should_create_organization_license() {
assertThat(result.get().getLicense()).isEqualTo("newLicense");
}

@Test
void should_not_create_organization_license_if_null_license() {
assertThat(service.getLicenseByOrganizationId("new")).isEmpty();

service.createOrUpdateOrganizationLicense("new", null);

var result = service.getLicenseByOrganizationId("new");
assertThat(result).isEmpty();
}

@Test
void should_update_organization_license() {
givenOrganizationLicense("org-to-update", "initialLicense");
Expand Down

0 comments on commit 83a50f5

Please sign in to comment.