planetarium / mimir

A backend service that provides 9c-related utility APIs.
https://nine-chronicles.dev/
GNU Affero General Public License v3.0
5 stars 22 forks source link

Add integration Test for Mimir dailyRewardReceivedBlockIndex Query #521

Closed Atralupus closed 2 days ago

Atralupus commented 4 days ago

We need to add a integration test for the dailyRewardReceivedBlockIndex query to ensure it returns the correct data.


Create DailyRewardQueryTest.cs with Initial integration Test

public class DailyRewardQueryTest
{
    [Fact]
    public async Task GraphQL_Query_DailyRewardReceivedBlockIndex_Returns_CorrectValue()
    {
    }
}

Mocking IServiceProvider with Mock DailyRewardRepository

  1. Create IDailyRewardRepository Interface:

    • Add the IDailyRewardRepository interface and apply it to DailyRewardRepository.
  2. Make DailyRewardRepository.GetReceivedBlockIndexAsync Virtual:

    • Modify the GetReceivedBlockIndexAsync method to be virtual for mocking.
  3. Mock Setup:

    [Fact]
    public async Task GraphQL_Query_DailyRewardReceivedBlockIndex_Returns_CorrectValue()
    {
    var mockAddress = new Address("0x0000000000000000000000000000000000000000");
    var mockRepo = new Mock<IDailyRewardRepository>();
    
    mockRepo
        .Setup(repo => repo.GetReceivedBlockIndexAsync(mockAddress))
        .ReturnsAsync(12345);
    
    var serviceProvider = TestServices.CreateServices(dailyRewardRepositoryMock: mockRepo);
    
    var query = """
    query {
      dailyRewardReceivedBlockIndex(address: "0x0000000000000000000000000000000000000000")
    }
    """;
    
    var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetQuery(query));
    
    await Verify(result);
    }

Notes

  1. Mocking:

    • The repository is mocked to return a predefined block index (e.g., 12345) for the test address.
  2. Verification:

    • The Verify method is used to validate the returned result matches the expected snapshot.
  3. Scenario Covered:

    • Test ensures that querying dailyRewardReceivedBlockIndex for a given address returns the correct block index.
nacoon53 commented 3 days ago

assign 부탁 드립니다.