-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...eryTests/BalanceQueryTest.GraphQL_Query_Balance_CRYSTAL_Returns_CorrectValue.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"balance": "fgfgf" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...s/QueryTests/BalanceQueryTest.GraphQL_Query_Balance_NCG_Returns_CorrectValue.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"balance": "fgfgf" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...yTests/BalanceQueryTest.GraphQL_Query_Balance_Throws_When_No_Inputs_Provided.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Either currency or currencyTicker must be provided.", | ||
"locations": [ | ||
{ | ||
"line": 2, | ||
"column": 7 | ||
} | ||
], | ||
"path": [ | ||
"balance" | ||
] | ||
} | ||
], | ||
"data": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using HotChocolate.AspNetCore; | ||
using Lib9c.GraphQL.Extensions; | ||
using Libplanet.Crypto; | ||
using Mimir.MongoDB.Bson; | ||
using Mimir.MongoDB.Repositories; | ||
using Moq; | ||
|
||
namespace Mimir.Tests.QueryTests; | ||
|
||
public class BalanceQueryTest | ||
{ | ||
[Fact] | ||
public async Task GraphQL_Query_Balance_CRYSTAL_Returns_CorrectValue() | ||
{ | ||
var mockAddress = new Address("0x0000000000000000000000000000000000000000"); | ||
var mockRepo = new Mock<IBalanceRepository>(); | ||
|
||
mockRepo | ||
.Setup(repo => repo.GetByAddressAsync("CRYSTAL".ToCurrency(), mockAddress)) | ||
.ReturnsAsync(new BalanceDocument(1, new Address(), "fgfgf")); | ||
|
||
var serviceProvider = TestServices.Builder | ||
.With(mockRepo.Object) | ||
.Build(); | ||
|
||
var query = $$""" | ||
query { | ||
balance(currencyTicker: "CRYSTAL", address: "{{mockAddress}}") | ||
} | ||
"""; | ||
|
||
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetDocument(query)); | ||
|
||
await Verify(result); | ||
} | ||
|
||
[Fact] | ||
public async Task GraphQL_Query_Balance_NCG_Returns_CorrectValue() | ||
{ | ||
var mockAddress = new Address("0x0000000000000000000000000000000000000000"); | ||
var mockRepo = new Mock<IBalanceRepository>(); | ||
|
||
mockRepo | ||
.Setup(repo => repo.GetByAddressAsync("NCG".ToCurrency(), mockAddress)) | ||
.ReturnsAsync(new BalanceDocument(1, new Address(), "fgfgf")); | ||
|
||
var serviceProvider = TestServices.Builder | ||
.With(mockRepo.Object) | ||
.Build(); | ||
|
||
var query = $$""" | ||
query { | ||
balance(currencyTicker: "NCG", address: "{{mockAddress}}") | ||
} | ||
"""; | ||
|
||
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetDocument(query)); | ||
|
||
await Verify(result); | ||
} | ||
|
||
[Fact] | ||
public async Task GraphQL_Query_Balance_Throws_When_No_Inputs_Provided() | ||
{ | ||
var mockRepo = new Mock<IBalanceRepository>(); | ||
|
||
var serviceProvider = TestServices.Builder | ||
.With(mockRepo.Object) | ||
.Build(); | ||
|
||
var query = $$""" | ||
query { | ||
balance(address: "0x0000000000000000000000000000000000000000") | ||
} | ||
"""; | ||
|
||
var result = await TestServices.ExecuteRequestAsync(serviceProvider, b => b.SetDocument(query)); | ||
await Verify(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters