File: clients_controller_test.rb

package info (click to toggle)
ruby-graphql 2.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,868 kB
  • sloc: ruby: 80,420; ansic: 1,808; yacc: 845; javascript: 480; makefile: 6
file content (65 lines) | stat: -rw-r--r-- 2,608 bytes parent folder | download
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
# frozen_string_literal: true
require "test_helper"

if defined?(GraphQL::Pro)
  class DashboardOperationStoreClientsControllerTest < ActionDispatch::IntegrationTest
    def test_it_manages_clients
      assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
      get graphql_dashboard.operation_store_clients_path
      assert_includes response.body, "0 Clients"
      assert_includes response.body, "To get started, create"

      get graphql_dashboard.new_operation_store_client_path
      assert_includes response.body, "New Client"

      post graphql_dashboard.operation_store_clients_path, params: {
        client: {
          name: "client-1",
          secret: "abcdefedcba"
        }
      }

      get graphql_dashboard.operation_store_clients_path
      assert_includes response.body, "1 Client"

      get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
      assert_includes response.body, "abcdefedcba"

      patch graphql_dashboard.operation_store_client_path(name: "client-1"), params: { client: { secret: "123456789" } }
      get graphql_dashboard.edit_operation_store_client_path(name: "client-1")
      assert_includes response.body, "123456789"

      delete graphql_dashboard.operation_store_client_path(name: "client-1")
      assert_equal 0, DummySchema.operation_store.all_clients(page: 1, per_page: 1).total_count
    ensure
      DummySchema.operation_store.delete_client("client-1")
    end

    def test_it_paginates
      5.times do |i|
        DummySchema.operation_store.upsert_client("client-#{i}", "abcdef")
      end
      get graphql_dashboard.operation_store_clients_path(per_page: 2)
      assert_includes response.body, "5 Clients"
      assert_includes response.body, "?page=2&amp;per_page=2"
      assert_includes response.body, "disabled>« prev</button>"

      get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 2)
      assert_includes response.body, "?page=1&amp;per_page=2"
      assert_includes response.body, "?page=3&amp;per_page=2"

      get graphql_dashboard.operation_store_clients_path(per_page: 2, page: 3)
      assert_includes response.body, "disabled>next »</button>"
      assert_includes response.body, "?page=2&amp;per_page=2"
    ensure
      5.times do |i|
        DummySchema.operation_store.delete_client("client-#{i}")
      end
    end

    def test_it_checks_installed
      get graphql_dashboard.new_operation_store_client_path, params: { schema: GraphQL::Schema }
      assert_includes response.body, "isn't installed for this schema yet"
    end
  end
end