GraphQLTest.php
2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Test\Integration;
require_once dirname(__DIR__) . '/Setup.php';
use Test\Setup;
use Braintree;
class GraphQLTest extends Setup
{
    public function testGraphQLPing()
    {
        Braintree\Configuration::environment('development');
        $graphQL = new Braintree\GraphQL(Braintree\Configuration::$global);
        $definition = "query { ping }";
        $response = $graphQL->request($definition, NULL);
        $this->assertEquals('pong', $response["data"]["ping"]);
    }
    public function testGraphQLProductionSSL()
    {
        Braintree\Configuration::environment('production');
        $graphQL = new Braintree\GraphQL(Braintree\Configuration::$global);
        $definition = "query { ping }";
        $this->setExpectedException('Braintree\Exception\Authentication');
        $response = $graphQL->request($definition, NULL);
    }
    public function testGraphQLSandboxSSL()
    {
        Braintree\Configuration::environment('sandbox');
        $graphQL = new Braintree\GraphQL(Braintree\Configuration::$global);
        $definition = "query { ping }";
        $this->setExpectedException('Braintree\Exception\Authentication');
        $response = $graphQL->request($definition, NULL);
    }
    public function testGraphQLWithVariableInputs()
    {
        Braintree\Configuration::environment('development');
        $graphQL = new Braintree\GraphQL(Braintree\Configuration::$global);
        $definition = '
mutation CreateClientToken($input: CreateClientTokenInput!) {
    createClientToken(input: $input) {
        clientMutationId
        clientToken
    }
}';
        $variables = [
          "input" => [
            "clientMutationId" => "abc123",
            "clientToken" => [
              "merchantAccountId" => "ABC123"
            ]
          ]
        ];
        $response = $graphQL->request($definition, $variables);
        $this->assertArrayNotHasKey("errors", $response);
        $this->assertTrue(is_string($response["data"]["createClientToken"]["clientToken"]));
    }
    public function testGraphQLWithVariableInputsCanReturnParsableErrors()
    {
        Braintree\Configuration::environment('development');
        $graphQL = new Braintree\GraphQL(Braintree\Configuration::$global);
        $definition = '
query TransactionLevelFeeReport($date: Date!, $merchantAccountId: ID) {
    report {
        transactionLevelFees(date: $date, merchantAccountId: $merchantAccountId) {
            url
        }
    }
}';
        $variables = [
            "date" => "2018-01-01",
            "merchantAccountId" => "some_merchant"
        ];
        $response = $graphQL->request($definition, $variables);
        $this->assertEquals("Invalid merchant account id: some_merchant", $response["errors"][0]["message"]);
    }
}