|
9 | 9 | let!(:store_credit_event) { create(:store_credit_adjustment_event, store_credit:, amount_remaining: 50) }
|
10 | 10 | let(:valid_params) { { amount: 100, store_credit_reason_id: create(:store_credit_reason).id } }
|
11 | 11 | let(:invalid_params) { { amount: nil } }
|
| 12 | + let(:valid_memo_params) { { memo: "Updated memo text" } } |
| 13 | + let(:invalid_memo_params) { { memo: nil } } |
12 | 14 |
|
13 | 15 | before do
|
14 | 16 | allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(admin_user)
|
|
78 | 80 | end
|
79 | 81 | end
|
80 | 82 |
|
| 83 | + describe "GET /edit_memo" do |
| 84 | + it "renders the edit_memo template with a 200 OK status" do |
| 85 | + get solidus_admin.edit_memo_user_store_credit_path(user, store_credit) |
| 86 | + expect(response).to have_http_status(:ok) |
| 87 | + expect(response.body).to include(store_credit.memo.to_s) |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + describe "PUT /update_memo" do |
| 92 | + context "with valid parameters" do |
| 93 | + it "updates the store credit memo" do |
| 94 | + expect { |
| 95 | + put solidus_admin.update_memo_user_store_credit_path(user, store_credit), params: { store_credit: valid_memo_params } |
| 96 | + }.to change { store_credit.reload.memo }.to("Updated memo text") |
| 97 | + end |
| 98 | + |
| 99 | + it "redirects to the store credit show page with a 303 See Other status" do |
| 100 | + put solidus_admin.update_memo_user_store_credit_path(user, store_credit), params: { store_credit: valid_memo_params } |
| 101 | + expect(response).to redirect_to(solidus_admin.user_store_credit_path(user, store_credit)) |
| 102 | + expect(response).to have_http_status(:see_other) |
| 103 | + end |
| 104 | + |
| 105 | + it "displays a success flash message" do |
| 106 | + put solidus_admin.update_memo_user_store_credit_path(user, store_credit), params: { store_credit: valid_memo_params } |
| 107 | + follow_redirect! |
| 108 | + expect(response.body).to include("Store credit was successfully updated.") |
| 109 | + end |
| 110 | + end |
| 111 | + |
| 112 | + context "when the database update fails" do |
| 113 | + before do |
| 114 | + # Memo update failures are nearly impossible to trigger due to lack of validation. |
| 115 | + allow_any_instance_of(Spree::StoreCredit).to receive(:update).and_return(false) |
| 116 | + end |
| 117 | + |
| 118 | + it "does not update the store credit memo" do |
| 119 | + expect { |
| 120 | + put solidus_admin.update_memo_user_store_credit_path(user, store_credit), params: { store_credit: valid_memo_params } |
| 121 | + }.not_to change { store_credit.reload.memo } |
| 122 | + end |
| 123 | + |
| 124 | + it "redirects to the store credit show page with a 303 See Other status" do |
| 125 | + put solidus_admin.update_memo_user_store_credit_path(user, store_credit), params: { store_credit: valid_memo_params } |
| 126 | + expect(response).to redirect_to(solidus_admin.user_store_credit_path(user, store_credit)) |
| 127 | + expect(response).to have_http_status(:see_other) |
| 128 | + end |
| 129 | + |
| 130 | + it "displays a failure flash message" do |
| 131 | + put solidus_admin.update_memo_user_store_credit_path(user, store_credit), params: { store_credit: valid_memo_params } |
| 132 | + follow_redirect! |
| 133 | + expect(response.body).to include("Something went wrong. Store credit could not be updated.") |
| 134 | + end |
| 135 | + end |
| 136 | + end |
| 137 | + |
81 | 138 | describe "private methods" do
|
82 | 139 | describe "#ensure_amount" do
|
83 | 140 | it "adds an error when the amount is blank" do
|
|
0 commit comments