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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metadata query test #554

Merged
merged 3 commits into from
Dec 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading