Skip to content

Commit

Permalink
adding test for allowing creation
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLewis-digirati committed Sep 23, 2024
1 parent cd9db66 commit 573cba0
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,51 @@ public async Task UpdateCollection_UpdatesCollection_WhenAllValuesProvided()
responseCollection.View.Id.Should().Contain("?page=1&pageSize=20");
}

[Fact]
public async Task UpdateCollection_CreatesCollection_WhenUnknownCollectionIdProvided()
{
// Arrange
var updatedCollection = new UpsertFlatCollection()
{
Behavior = new List<string>()
{
Behavior.IsPublic,
Behavior.IsStorageCollection
},
Label = new LanguageMap("en", ["test collection - create from update"]),
Slug = "create-from-update",
Parent = parent,
ItemsOrder = 1,
Thumbnail = "some/location/2",
Tags = "some, tags, 2",
};

var updateRequestMessage = HttpRequestMessageBuilder.GetPrivateRequest(HttpMethod.Put,
$"{Customer}/collections/createFromUpdate", JsonSerializer.Serialize(updatedCollection));

// Act
var response = await httpClient.AsCustomer(1).SendAsync(updateRequestMessage);

var responseCollection = await response.ReadAsPresentationResponseAsync<FlatCollection>();

var fromDatabase = dbContext.Collections.First(c => c.Id == responseCollection!.Id!.Split('/', StringSplitOptions.TrimEntries).Last());

// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
fromDatabase.Id.Should().Be("createFromUpdate");
fromDatabase.Parent.Should().Be(parent);
fromDatabase.Label!.Values.First()[0].Should().Be("test collection - create from update");
fromDatabase.Slug.Should().Be("create-from-update");
fromDatabase.ItemsOrder.Should().Be(1);
fromDatabase.Thumbnail.Should().Be("some/location/2");
fromDatabase.Tags.Should().Be("some, tags, 2");
fromDatabase.IsPublic.Should().BeTrue();
fromDatabase.IsStorageCollection.Should().BeTrue();
responseCollection!.View!.PageSize.Should().Be(20);
responseCollection.View.Page.Should().Be(1);
responseCollection.View.Id.Should().Contain("?page=1&pageSize=20");
}

[Fact]
public async Task UpdateCollection_UpdatesCollection_WhenAllValuesProvidedWithoutLabel()
{
Expand Down

0 comments on commit 573cba0

Please sign in to comment.