Module: WikidataAdaptor::TestHelpers::RestApi::Aliases

Included in:
WikidataAdaptor::TestHelpers::RestApi
Defined in:
lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb

Overview

WebMock stubs for Wikibase REST API alias endpoints

Instance Method Summary collapse

Instance Method Details

#stub_get_item_alias(item_id, language_code) ⇒ Object

GET /v1/entities/items/:item_id/aliases/:language_code



30
31
32
33
34
35
36
37
38
39
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 30

def stub_get_item_alias(item_id, language_code)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}/aliases/#{language_code}",
    response_body: [
      "Douglas Noel Adams",
      "Douglas Noël Adams"
    ]
  )
end

#stub_get_item_aliases(item_id) ⇒ Object

GET /v1/entities/items/:item_id/aliases



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 11

def stub_get_item_aliases(item_id)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}/aliases",
    response_body: {
      en: [
        "Douglas Noel Adams",
        "Douglas Noël Adams"
      ],
      fr: [
        "Douglas Noel Adams"
      ]
    }
  )
end

#stub_get_property_alias(property_id, language_code) ⇒ Object

GET /v1/entities/properties/:property_id/aliases/:language_code



109
110
111
112
113
114
115
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 109

def stub_get_property_alias(property_id, language_code)
  stub_rest_api_request(
    :get,
    "/v1/entities/properties/#{property_id}/aliases/#{language_code}",
    response_body: ["is a"]
  )
end

#stub_get_property_aliases(property_id) ⇒ Object

GET /v1/entities/properties/:property_id/aliases



95
96
97
98
99
100
101
102
103
104
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 95

def stub_get_property_aliases(property_id)
  stub_rest_api_request(
    :get,
    "/v1/entities/properties/#{property_id}/aliases",
    response_body: {
      en: ["is a"],
      fr: ["est un"]
    }
  )
end

#stub_patch_item_aliases(item_id, payload, response_body: nil) ⇒ Object

PATCH /v1/entities/items/:item_id/aliases



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 171

def stub_patch_item_aliases(item_id, payload, response_body: nil)
  stub_rest_api_request(
    :patch,
    "/v1/entities/items/#{item_id}/aliases",
    with: { body: payload.to_json },
    response_body: response_body || {
      en: ["Douglas Noel Adams", "Douglas Noël Adams", "DNA"],
      fr: ["Douglas Noel Adams"]
    }
  )
end

#stub_patch_item_aliases_unexpected_error(item_id, payload) ⇒ WebMock::RequestStub

Stub PATCH item aliases request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


189
190
191
192
193
194
195
196
197
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 189

def stub_patch_item_aliases_unexpected_error(item_id, payload)
  stub_rest_api_request(
    :patch,
    "/v1/entities/items/#{item_id}/aliases",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_patch_property_aliases(property_id, payload, response_body: nil) ⇒ Object

PATCH /v1/entities/properties/:property_id/aliases



202
203
204
205
206
207
208
209
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 202

def stub_patch_property_aliases(property_id, payload, response_body: nil)
  stub_rest_api_request(
    :patch,
    "/v1/entities/properties/#{property_id}/aliases",
    with: { body: payload.to_json },
    response_body: response_body || { en: ["is a", "is an"], fr: ["est un"] }
  )
end

#stub_patch_property_aliases_unexpected_error(property_id, payload) ⇒ WebMock::RequestStub

Stub PATCH property aliases request returning 500 error

Parameters:

  • property_id (String)

    The property ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


217
218
219
220
221
222
223
224
225
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 217

def stub_patch_property_aliases_unexpected_error(property_id, payload)
  stub_rest_api_request(
    :patch,
    "/v1/entities/properties/#{property_id}/aliases",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_post_item_aliases(item_id, language_code, payload, response_body: nil) ⇒ Object

POST /v1/entities/items/:item_id/aliases/:language_code



44
45
46
47
48
49
50
51
52
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 44

def stub_post_item_aliases(item_id, language_code, payload, response_body: nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/items/#{item_id}/aliases/#{language_code}",
    response_status: 200,
    with: { body: payload.to_json },
    response_body: response_body || ["Douglas Noel Adams", "Douglas Noël Adams"]
  )
end

#stub_post_item_aliases_created(item_id, language_code, payload, response_body: nil) ⇒ WebMock::RequestStub

Stub POST item aliases request returning 201 Created

Parameters:

  • item_id (String)

    The item ID

  • language_code (String)

    The language code

  • payload (Hash)

    The request payload

  • response_body (Array<String>, nil) (defaults to: nil)

    Optional custom response

Returns:

  • (WebMock::RequestStub)


62
63
64
65
66
67
68
69
70
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 62

def stub_post_item_aliases_created(item_id, language_code, payload, response_body: nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/items/#{item_id}/aliases/#{language_code}",
    response_status: 201,
    with: { body: payload.to_json },
    response_body: response_body || ["Douglas Noel Adams", "Douglas Noël Adams"]
  )
end

#stub_post_item_aliases_unexpected_error(item_id, language_code, payload) ⇒ WebMock::RequestStub

Stub POST item aliases request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • language_code (String)

    The language code

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 79

def stub_post_item_aliases_unexpected_error(item_id, language_code, payload)
  stub_rest_api_request(
    :post,
    "/v1/entities/items/#{item_id}/aliases/#{language_code}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: {
      code: "unexpected-error",
      message: "Unexpected Error"
    }
  )
end

#stub_post_property_aliases(property_id, language_code, payload, response_body: nil) ⇒ Object

POST /v1/entities/properties/:property_id/aliases/:language_code



120
121
122
123
124
125
126
127
128
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 120

def stub_post_property_aliases(property_id, language_code, payload, response_body: nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/properties/#{property_id}/aliases/#{language_code}",
    response_status: 200,
    with: { body: payload.to_json },
    response_body: response_body || ["is a", "is an"]
  )
end

#stub_post_property_aliases_created(property_id, language_code, payload, response_body: nil) ⇒ WebMock::RequestStub

Stub POST property aliases request returning 201 Created

Parameters:

  • property_id (String)

    The property ID

  • language_code (String)

    The language code

  • payload (Hash)

    The request payload

  • response_body (Array<String>, nil) (defaults to: nil)

    Optional custom response

Returns:

  • (WebMock::RequestStub)


138
139
140
141
142
143
144
145
146
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 138

def stub_post_property_aliases_created(property_id, language_code, payload, response_body: nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/properties/#{property_id}/aliases/#{language_code}",
    response_status: 201,
    with: { body: payload.to_json },
    response_body: response_body || ["is a", "is an"]
  )
end

#stub_post_property_aliases_unexpected_error(property_id, language_code, payload) ⇒ WebMock::RequestStub

Stub POST property aliases request returning 500 error

Parameters:

  • property_id (String)

    The property ID

  • language_code (String)

    The language code

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb', line 155

def stub_post_property_aliases_unexpected_error(property_id, language_code, payload)
  stub_rest_api_request(
    :post,
    "/v1/entities/properties/#{property_id}/aliases/#{language_code}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: {
      code: "unexpected-error",
      message: "Unexpected Error"
    }
  )
end