Skip to content

Commit

Permalink
Merge pull request #554 from DONALDSUK/main
Browse files Browse the repository at this point in the history
add metadata query test
  • Loading branch information
Atralupus authored Dec 4, 2024
2 parents b017fbc + a693efd commit e397e4a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Mimir.MongoDB/Repositories/MetadataRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
using MongoDB.Driver;

namespace Mimir.MongoDB.Repositories;

public class MetadataRepository(IMongoDbService dbService)
public interface IMetadataRepository{
Task<MetadataDocument> GetByCollectionAsync(string collectionName);
Task<MetadataDocument> GetByCollectionAndTypeAsync(
string pollerType,
string collectionName);
}
public class MetadataRepository(IMongoDbService dbService):IMetadataRepository
{
public async Task<MetadataDocument> GetByCollectionAsync(string collectionName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"data": {
"metadata": {
"collectionName": "collection",
"latestBlockIndex": 0,
"pollerType": "poller-type"
}
}
}
38 changes: 38 additions & 0 deletions Mimir.Tests/QueryTests/MetadataTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Libplanet.Crypto;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Repositories;
using Mimir.Tests;
using Moq;

public class MetadataTest
{
[Fact]
public async Task GraphQL_Query_Metadata_Returns_CorrectValue()
{
var mockRepo = new Mock<IMetadataRepository>();
mockRepo
.Setup(repo => repo.GetByCollectionAsync(It.IsAny<string>()))
.ReturnsAsync(new MetadataDocument{
PollerType="poller-type",
CollectionName="collection"
});

var serviceProvider = TestServices.Builder
.With(mockRepo.Object)
.Build();

var query = $$"""
query {
metadata(collectionName: "collection") {
collectionName
latestBlockIndex
pollerType
}
}
""";

var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetDocument(query));

await Verify(result);
}
}
2 changes: 1 addition & 1 deletion Mimir/GraphQL/Queries/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task<Inventory> GetInventoryAsync(Address address, [Service] IInven
/// </summary>
/// <param name="collectionName">The name of the collection.</param>
/// <returns>The metadata</returns>
public async Task<MetadataDocument> GetMetadataAsync(string collectionName, [Service] MetadataRepository repo) =>
public async Task<MetadataDocument> GetMetadataAsync(string collectionName, [Service] IMetadataRepository repo) =>
await repo.GetByCollectionAsync(collectionName);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Mimir/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
builder.Services.AddSingleton<IDailyRewardRepository, DailyRewardRepository>();
builder.Services.AddSingleton<IInventoryRepository, InventoryRepository>();
builder.Services.AddSingleton<ItemSlotRepository>();
builder.Services.AddSingleton<MetadataRepository>();
builder.Services.AddSingleton<IMetadataRepository,MetadataRepository>();
builder.Services.AddSingleton<PetRepository>();
builder.Services.AddSingleton<PledgeRepository>();
builder.Services.AddSingleton<ProductRepository>();
Expand Down

0 comments on commit e397e4a

Please sign in to comment.