Skip to content

Commit

Permalink
Implemented test for adding portal admins that does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kjetilhau committed Dec 5, 2024
1 parent 856188e commit 8b0d235
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data;

internal static class FusionProfileApiData
{
public static Guid ValidProfileAzureUniquePersonId = new(UserData.AuthenticatedUserWithPortalAdminId);
public static Guid NonExistentAzureUniquePersonId = new (UserData.NonExistentUserId);
public static Guid ValidAzureUniquePersonId = new(UserData.AuthenticatedUserWithPortalAdminId);

public static readonly ResolvedPersonProfile ValidResolvedProfile = new(new FusionPersonProfile(FusionAccountType.External, string.Empty, ValidProfileAzureUniquePersonId, "Name"))
public static readonly ResolvedPersonProfile ValidResolvedProfile = new(new FusionPersonProfile(FusionAccountType.External, string.Empty, ValidAzureUniquePersonId, "Some Name"))
{
Identifier = ValidProfile,
Identifier = ValidPerson,
Success = true,
StatusCode = 200,
Profile = new FusionPersonProfile(FusionAccountType.External, string.Empty, ValidProfileAzureUniquePersonId, "Name"),
Profile = new FusionPersonProfile(FusionAccountType.External, string.Empty, ValidAzureUniquePersonId, "Name"),
Message = string.Empty
};

public static PersonIdentifier ValidProfile => new(ValidProfileAzureUniquePersonId);
public static PersonIdentifier ValidPerson => new(ValidAzureUniquePersonId);

public static List<ResolvedPersonProfile> ValidFusionProfiles => [ValidResolvedProfile];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Equinor.ProjectExecutionPortal.Tests.WebApi.Data;

internal static class UserData
{
public const string NonExistentUserId = "01010101-0000-0000-0000-010101010101";
public const string AuthenticatedUserId = "11111111-0000-0000-0000-222222222222";
public const string AuthenticatedUserWithPortalAdminId = "22222222-0000-0000-0000-333333333333";
public const string AdministratorUserId = "66666666-0000-0000-0000-999999999999";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ public async Task Create_Portal_AsAdministratorUser_ShouldReturnOk()
Assert.AreEqual(payload.ContextTypes.Count, createdPortal.ContextTypes.Count);
}

[TestMethod]
public async Task Create_Portal_AsAdministrator_WithInvalidAdmin_ShouldReturnBadRequest()
{
// Arrange
var getAllBeforeCreation = await AssertGetAllPortals(UserType.Administrator, HttpStatusCode.OK);

var payload = new ApiCreatePortalRequest
{
Name = "Created portal name",
Description = "Created description",
ShortName = "Created short name",
Subtext = "Created subtext",
Icon = "Created icon",
ContextTypes = [ContextTypeData.ValidContextTypes.ProjectMasterContextTypeKey],
Admins = [new ApiAccountIdentifier { AzureUniqueId = FusionProfileApiData.NonExistentAzureUniquePersonId }]
};

// Act
var response = await CreatePortal(UserType.Administrator, payload);
var getAllAfterCreation = await AssertGetAllPortals(UserType.Administrator, HttpStatusCode.OK);

// Assert
Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
Assert.AreEqual(getAllBeforeCreation!.Count, getAllAfterCreation!.Count);
}

[TestMethod]
public async Task Create_Portal_AsAuthenticatedUser_ShouldReturnForbidden()
{
Expand Down

0 comments on commit 8b0d235

Please sign in to comment.