forked from DigixGlobal/dao-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DigixGlobal#70 tests for watched_transaction_resolver
- Loading branch information
1 parent
e02e227
commit b329457
Showing
2 changed files
with
45 additions
and
2 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
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class UserQueryTest < ActiveSupport::TestCase | ||
QUERY = <<~EOS | ||
query($txhash: String!) { | ||
watchedTransaction(txhash: $txhash) { | ||
id | ||
} | ||
} | ||
EOS | ||
|
||
test 'watched transaction should work' do | ||
first_transaction = create(:watching_transaction) | ||
sleep 1 | ||
last_transaction = create(:watching_transaction, group_id: first_transaction.group_id, user: first_transaction.user) | ||
result = DaoServerSchema.execute( | ||
QUERY, | ||
context: { current_user: first_transaction.user }, | ||
variables: { txhash: first_transaction.txhash } | ||
) | ||
|
||
assert_nil result['errors'], | ||
'should work and have no errors' | ||
|
||
data = result['data']['watchedTransaction'] | ||
|
||
assert_not_empty data, | ||
'watchedTransaction type should work' | ||
assert_equal last_transaction.id, data['id'], | ||
'should return last transaction from group' | ||
|
||
empty_result = DaoServerSchema.execute( | ||
QUERY, | ||
context: { current_user: first_transaction.user }, | ||
variables: { txhash: 'NON_EXISTENT_TXHASH' } | ||
) | ||
|
||
assert_nil empty_result['data']['watchedTransaction'], | ||
'data should be empty on invalid txhash' | ||
end | ||
end |