Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service): only create org license if license non-null #6945

Merged
merged 1 commit into from Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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