blob: bf33067c3a1b2eeefb7833d1736eaf805b95c94b (
plain)
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
|
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'DELETE /api/account/addresses/address_id', type: :request do
let(:user) { create(:user_account, role: 'regular') }
let(:token) { jwt(user) }
let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
let(:address) { create(:address) }
before(:each) do
relate_user_and_address(user, address)
end
it_behaves_like 'a DELETE request' do
let(:resource) { "/api/account/addresses/#{address.id}" }
let(:nonexistent_resource) { "/api/account/addresses/#{SecureRandom.hex(8)}" }
end
context 'when the address belongs to other users' do
it "doesn't get deleted" do
another_user = create(:user_account, role: 'regular')
relate_user_and_address(another_user, address)
delete("/api/account/addresses/#{address.id}", headers:)
expect(Address.find_by(id: address.id)).to_not be_nil
end
end
context "when the address doesn't belong to other users" do
it 'gets deleted' do
delete("/api/account/addresses/#{address.id}", headers:)
expect(Address.find_by(id: address.id)).to be_nil
end
end
end
|