2020-02-27 13:09:21 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Graphql::Docs::Renderer do
|
2020-02-27 13:09:21 -05:00
|
|
|
describe '#contents' do
|
|
|
|
# Returns a Schema that uses the given `type`
|
|
|
|
def mock_schema(type)
|
2020-03-20 05:09:22 -04:00
|
|
|
query_type = Class.new(Types::BaseObject) do
|
2020-02-27 13:09:21 -05:00
|
|
|
graphql_name 'QueryType'
|
|
|
|
|
|
|
|
field :foo, type, null: true
|
|
|
|
end
|
|
|
|
|
|
|
|
GraphQL::Schema.define(query: query_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
let_it_be(:template) { Rails.root.join('lib/gitlab/graphql/docs/templates/', 'default.md.haml') }
|
|
|
|
|
|
|
|
subject(:contents) do
|
|
|
|
described_class.new(
|
|
|
|
mock_schema(type).graphql_definition,
|
|
|
|
output_dir: nil,
|
|
|
|
template: template
|
|
|
|
).contents
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'A type with a field with a [Array] return type' do
|
|
|
|
let(:type) do
|
2020-03-20 05:09:22 -04:00
|
|
|
Class.new(Types::BaseObject) do
|
2020-02-27 13:09:21 -05:00
|
|
|
graphql_name 'ArrayTest'
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
field :foo, [GraphQL::STRING_TYPE], null: false, description: 'A description.'
|
2020-02-27 13:09:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expectation = <<~DOC
|
2020-09-11 05:08:44 -04:00
|
|
|
### ArrayTest
|
2020-02-27 13:09:21 -05:00
|
|
|
|
2020-09-11 05:08:44 -04:00
|
|
|
| Field | Type | Description |
|
|
|
|
| ----- | ---- | ----------- |
|
2020-12-11 10:10:04 -05:00
|
|
|
| `foo` | String! => Array | A description. |
|
2020-02-27 13:09:21 -05:00
|
|
|
DOC
|
|
|
|
|
|
|
|
is_expected.to include(expectation)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'A type with fields defined in reverse alphabetical order' do
|
|
|
|
let(:type) do
|
2020-03-20 05:09:22 -04:00
|
|
|
Class.new(Types::BaseObject) do
|
2020-02-27 13:09:21 -05:00
|
|
|
graphql_name 'OrderingTest'
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
field :foo, GraphQL::STRING_TYPE, null: false, description: 'A description of foo field.'
|
|
|
|
field :bar, GraphQL::STRING_TYPE, null: false, description: 'A description of bar field.'
|
2020-02-27 13:09:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expectation = <<~DOC
|
2020-09-11 05:08:44 -04:00
|
|
|
### OrderingTest
|
2020-02-27 13:09:21 -05:00
|
|
|
|
2020-09-11 05:08:44 -04:00
|
|
|
| Field | Type | Description |
|
|
|
|
| ----- | ---- | ----------- |
|
2020-12-11 10:10:04 -05:00
|
|
|
| `bar` | String! | A description of bar field. |
|
|
|
|
| `foo` | String! | A description of foo field. |
|
2020-02-27 13:09:21 -05:00
|
|
|
DOC
|
|
|
|
|
|
|
|
is_expected.to include(expectation)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'A type with a deprecated field' do
|
|
|
|
let(:type) do
|
2020-03-20 05:09:22 -04:00
|
|
|
Class.new(Types::BaseObject) do
|
2020-02-27 13:09:21 -05:00
|
|
|
graphql_name 'DeprecatedTest'
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
field :foo, GraphQL::STRING_TYPE, null: false, deprecated: { reason: 'This is deprecated', milestone: '1.10' }, description: 'A description.'
|
2020-02-27 13:09:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expectation = <<~DOC
|
2020-09-11 05:08:44 -04:00
|
|
|
### DeprecatedTest
|
2020-02-27 13:09:21 -05:00
|
|
|
|
2020-09-11 05:08:44 -04:00
|
|
|
| Field | Type | Description |
|
|
|
|
| ----- | ---- | ----------- |
|
2020-12-11 10:10:04 -05:00
|
|
|
| `foo` **{warning-solid}** | String! | **Deprecated:** This is deprecated. Deprecated in 1.10. |
|
2020-02-27 13:09:21 -05:00
|
|
|
DOC
|
|
|
|
|
|
|
|
is_expected.to include(expectation)
|
|
|
|
end
|
|
|
|
end
|
2020-09-11 05:08:44 -04:00
|
|
|
|
|
|
|
context 'A type with an emum field' do
|
|
|
|
let(:type) do
|
|
|
|
enum_type = Class.new(Types::BaseEnum) do
|
|
|
|
graphql_name 'MyEnum'
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
value 'BAZ', description: 'A description of BAZ.'
|
|
|
|
value 'BAR', description: 'A description of BAR.', deprecated: { reason: 'This is deprecated', milestone: '1.10' }
|
2020-09-11 05:08:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Class.new(Types::BaseObject) do
|
|
|
|
graphql_name 'EnumTest'
|
|
|
|
|
2020-12-11 10:10:04 -05:00
|
|
|
field :foo, enum_type, null: false, description: 'A description of foo field.'
|
2020-09-11 05:08:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expectation = <<~DOC
|
|
|
|
### MyEnum
|
|
|
|
|
|
|
|
| Value | Description |
|
|
|
|
| ----- | ----------- |
|
2020-12-11 10:10:04 -05:00
|
|
|
| `BAR` **{warning-solid}** | **Deprecated:** This is deprecated. Deprecated in 1.10. |
|
|
|
|
| `BAZ` | A description of BAZ. |
|
2020-09-11 05:08:44 -04:00
|
|
|
DOC
|
|
|
|
|
|
|
|
is_expected.to include(expectation)
|
|
|
|
end
|
|
|
|
end
|
2020-02-27 13:09:21 -05:00
|
|
|
end
|
|
|
|
end
|