|
7 | 7 | { |
8 | 8 | date: '2016-01-01 12:00:00', |
9 | 9 | currency: 'USD', |
| 10 | + disabled: false, |
| 11 | + disabled_at: nil, |
| 12 | + disabled_by: nil, |
| 13 | + edit_history_summary: { |
| 14 | + values_changed: { |
| 15 | + amount_in_cents: { |
| 16 | + original_value: 900, |
| 17 | + edited_value: 1000 |
| 18 | + } |
| 19 | + }, |
| 20 | + latest_edit_author: 'admin@example.com', |
| 21 | + latest_edit_performed_at: '2024-01-10T12:00:00.000Z' |
| 22 | + }, |
| 23 | + errors: nil, |
10 | 24 | line_items: [ |
11 | 25 | { |
12 | 26 | type: 'subscription', |
|
273 | 287 | ) |
274 | 288 | end |
275 | 289 | end |
| 290 | + |
| 291 | + context 'with query params' do |
| 292 | + it 'accepts validation_type=all in list', uses_api: false do |
| 293 | + allow(ChartMogul::Invoices).to receive(:connection).and_return(double('connection')) |
| 294 | + expect(ChartMogul::Invoices.connection).to receive(:get) do |path| |
| 295 | + expect(path).to eq('/v1/invoices?validation_type=all') |
| 296 | + double('response', body: '{"invoices": [], "cursor": null, "has_more": false}') |
| 297 | + end |
| 298 | + |
| 299 | + described_class.all(validation_type: 'all') |
| 300 | + end |
| 301 | + |
| 302 | + it_behaves_like 'retrieve with query params', 'inv_94d194de-04fa-4c81-8871-cc78af388eb3', |
| 303 | + { validation_type: 'all', include_edit_history: true, with_disabled: true }, |
| 304 | + <<-JSON, |
| 305 | + { |
| 306 | + "uuid": "inv_94d194de-04fa-4c81-8871-cc78af388eb3", |
| 307 | + "external_id": "test", |
| 308 | + "currency": "USD", |
| 309 | + "disabled": true, |
| 310 | + "disabled_at": "2024-01-15T10:30:00.000Z", |
| 311 | + "disabled_by": "user@example.com", |
| 312 | + "edit_history_summary": { |
| 313 | + "values_changed": { |
| 314 | + "currency": { |
| 315 | + "original_value": "EUR", |
| 316 | + "edited_value": "USD" |
| 317 | + }, |
| 318 | + "date": { |
| 319 | + "original_value": "2024-01-01T00:00:00.000Z", |
| 320 | + "edited_value": "2024-01-02T00:00:00.000Z" |
| 321 | + } |
| 322 | + }, |
| 323 | + "latest_edit_author": "editor@example.com", |
| 324 | + "latest_edit_performed_at": "2024-01-20T15:45:00.000Z" |
| 325 | + }, |
| 326 | + "errors": { |
| 327 | + "currency": ["Currency is invalid", "Currency must be supported"], |
| 328 | + "date": ["Date is in the future"] |
| 329 | + } |
| 330 | + } |
| 331 | + JSON |
| 332 | + lambda { |invoice| |
| 333 | + expect(invoice.disabled).to eq(true) |
| 334 | + expect(invoice.disabled_at).to eq('2024-01-15T10:30:00.000Z') |
| 335 | + expect(invoice.disabled_by).to eq('user@example.com') |
| 336 | + expect(invoice.edit_history_summary).to be_a(Hash) |
| 337 | + expect(invoice.edit_history_summary[:values_changed]).to be_a(Hash) |
| 338 | + expect(invoice.edit_history_summary[:values_changed][:currency][:original_value]).to eq('EUR') |
| 339 | + expect(invoice.edit_history_summary[:values_changed][:currency][:edited_value]).to eq('USD') |
| 340 | + expect(invoice.edit_history_summary[:latest_edit_author]).to eq('editor@example.com') |
| 341 | + expect(invoice.edit_history_summary[:latest_edit_performed_at]).to eq('2024-01-20T15:45:00.000Z') |
| 342 | + expect(invoice.errors).to be_a(Hash) |
| 343 | + expect(invoice.errors[:currency]).to be_an(Array) |
| 344 | + expect(invoice.errors[:currency].length).to eq(2) |
| 345 | + expect(invoice.errors[:currency][0]).to eq('Currency is invalid') |
| 346 | + expect(invoice.errors[:currency][1]).to eq('Currency must be supported') |
| 347 | + expect(invoice.errors[:date]).to be_an(Array) |
| 348 | + expect(invoice.errors[:date].length).to eq(1) |
| 349 | + expect(invoice.errors[:date][0]).to eq('Date is in the future') |
| 350 | + } |
| 351 | + end |
276 | 352 | end |
277 | 353 | end |
0 commit comments