Module: WikidataAdaptor::TestHelpers::RestApi::Items

Includes:
Support
Included in:
WikidataAdaptor::TestHelpers::RestApi
Defined in:
lib/wikidata_adaptor/test_helpers/rest_api/items.rb

Overview

WebMock stubs for Wikibase REST API items endpoints

Instance Method Summary collapse

Methods included from Support

#load_openapi_spec, #load_path_example, #posted_item_payload_fixture, #posted_item_response_fixture, #posted_property_payload_fixture, #posted_property_response_fixture

Instance Method Details

#stub_get_item(item_id, response_body = nil) ⇒ Object

GET /v1/entities/items/:item_id



14
15
16
17
18
19
20
21
22
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 14

def stub_get_item(item_id, response_body = nil)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}",
    response_body: response_body || load_path_example(
      "/v1/entities/items/{item_id}", "get"
    )
  )
end

#stub_get_item_invalid_item(item_id) ⇒ WebMock::RequestStub

Stub GET item request returning 400 invalid item error

Parameters:

  • item_id (String)

    The item ID

Returns:

  • (WebMock::RequestStub)


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

def stub_get_item_invalid_item(item_id)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}",
    response_status: 400,
    response_body: {
      code: "invalid-item-id",
      message: "Not a valid item ID: {#{item_id}}"
    }
  )
end

#stub_get_item_not_found(item_id) ⇒ WebMock::RequestStub

Stub GET item request returning 404 not found error

Parameters:

  • item_id (String)

    The item ID

Returns:

  • (WebMock::RequestStub)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 46

def stub_get_item_not_found(item_id)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}",
    response_status: 404,
    response_body: {
      code: "item-not-found",
      message: "Could not find an item with the ID: {#{item_id}}"
    }
  )
end

#stub_get_item_unexpected_error(item_id) ⇒ WebMock::RequestStub

Stub GET item request returning 500 error

Parameters:

  • item_id (String)

    The item ID

Returns:

  • (WebMock::RequestStub)


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 63

def stub_get_item_unexpected_error(item_id)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}",
    response_status: 500,
    response_body: {
      code: "unexpected-error",
      message: "Unexpected Error"
    }
  )
end

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

PATCH /v1/entities/items/:item_id



184
185
186
187
188
189
190
191
192
193
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 184

def stub_patch_item(item_id, payload, response_body: nil)
  stub_rest_api_request(
    :patch,
    "/v1/entities/items/#{item_id}",
    with: { body: payload.to_json },
    response_body: response_body || load_path_example(
      "/v1/entities/items/{item_id}", "get"
    )
  )
end

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

Stub PATCH item request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


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

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

#stub_post_item(payload, response_body = nil) ⇒ Object

POST /v1/entities/items



78
79
80
81
82
83
84
85
86
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 78

def stub_post_item(payload, response_body = nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/items",
    response_status: 201,
    with: { body: payload.to_json },
    response_body: response_body || posted_item_response_fixture.to_json
  )
end

#stub_post_item_access_deniedWebMock::RequestStub

Stub POST item request returning 403 access denied error

Returns:

  • (WebMock::RequestStub)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 108

def stub_post_item_access_denied
  stub_rest_api_request(
    :post,
    "/v1/entities/items",
    response_status: 403,
    response_body: {
      code: "permission-denied",
      message: "Access to resource is denied",
      context: {
        denial_reason: "{reason_code}",
        denial_context: "{additional_context}"
      }
    }
  )
end

#stub_post_item_data_policy_violationWebMock::RequestStub

Stub POST item request returning 422 data policy violation error

Returns:

  • (WebMock::RequestStub)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 127

def stub_post_item_data_policy_violation
  stub_rest_api_request(
    :post,
    "/v1/entities/items",
    response_status: 422,
    response_body: {
      code: "data-policy-violation",
      message: "Edit violates data policy",
      context: {
        violation: "{violation_code}",
        violation_context: {
          some: "context"
        }
      }
    }
  )
end

#stub_post_item_invalid_item(response_body = nil) ⇒ WebMock::RequestStub

Stub POST item request returning 400 invalid item error

Parameters:

  • response_body (Hash, nil) (defaults to: nil)

    Optional response body

Returns:

  • (WebMock::RequestStub)


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

def stub_post_item_invalid_item(response_body = nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/items",
    response_status: 400,
    response_body: response_body || {
      code: "invalid-item-data",
      message: "The provided item data is invalid."
    }
  )
end

#stub_post_item_request_limit_reachedWebMock::RequestStub

Stub POST item request returning 429 request limit reached error

Returns:

  • (WebMock::RequestStub)


148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 148

def stub_post_item_request_limit_reached
  stub_rest_api_request(
    :post,
    "/v1/entities/items",
    response_status: 429,
    response_body: {
      code: "request-limit-reached",
      message: "Exceeded the limit of actions that can be performed in a given span of time",
      context: {
        reason: "{reason_code}"
      }
    }
  )
end

#stub_post_item_unexpected_error(payload) ⇒ WebMock::RequestStub

Stub POST item request returning 500 error

Parameters:

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/wikidata_adaptor/test_helpers/rest_api/items.rb', line 168

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