Skip to content

Commit

Permalink
PIDP-1093 Add isPharm Keycloak Attribute (#630)
Browse files Browse the repository at this point in the history
* set attribute

* make tests pass

* alphabetize

* reformat

---------

Co-authored-by: James Hollinger <[email protected]>
Co-authored-by: James Hollinger <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 5537f20 commit 287f483
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ public async void UpdateKeycloakAfterCollegeLicenceUpdated_OneLicence_BusPushedW

var message = capturedMessages.Single();
Assert.Equal(party.PrimaryUserId, message.UserId);
Assert.Single(message.Attributes);
Assert.Equal(2, message.Attributes.Count);

var attribute = message.Attributes.Single();
Assert.Equal("college_licence_info", attribute.Key);
Assert.Single(attribute.Value);
var attribute1 = message.Attributes.Single(a => a.Key == "college_licence_info");
Assert.Equal("college_licence_info", attribute1.Key);
Assert.Single(attribute1.Value);

var busRecords = JsonSerializer.Deserialize<IEnumerable<PlrRecord>>(attribute.Value[0], new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })!;
var attribute2 = message.Attributes.Single(a => a.Key == "is_pharm");
Assert.Equal("is_pharm", attribute2.Key);
Assert.Single(attribute2.Value);

var busRecords = JsonSerializer.Deserialize<IEnumerable<PlrRecord>>(attribute1.Value[0], new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })!;

AssertThat.CollectionsAreEquivalent(expectedRecords, busRecords, (expected, bus) =>
expected.CollegeId == bus.CollegeId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ public async Task Handle(CollegeLicenceUpdated notification, CancellationToken c
return;
}

var isPharmacist = PlrStandingsDigest.FromRecords(records)
.With(IdentifierType.Pharmacist)
.HasGoodStanding;

foreach (var userId in party.Credentials.Select(credential => credential.UserId))
{
await this.bus.Publish(UpdateKeycloakAttributes.FromUpdateAction(userId, user => user.SetCollegeLicenceInformation(records)), cancellationToken);
await this.bus.Publish(UpdateKeycloakAttributes.FromUpdateAction(userId, user => user
.SetCollegeLicenceInformation(records)
.SetIsPharm(isPharmacist)), cancellationToken);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public UserRepresentation SetCollegeLicenceInformation(IEnumerable<PlrRecord> pl

public UserRepresentation SetCpn(string cpn) => this.SetAttribute("common_provider_number", cpn);

public UserRepresentation SetIsPharm(bool isPharm) => this.SetAttribute("is_pharm", isPharm.ToString());

internal UserRepresentation SetLdapOrgDetails(LdapLoginResponse.OrgDetails orgDetails) => this.SetAttribute("org_details", JsonSerializer.Serialize(orgDetails, SerializationOptions));

public UserRepresentation SetOpId(string opId) => this.SetAttribute("opId", opId);
Expand Down

0 comments on commit 287f483

Please sign in to comment.