|
19 | 19 | end |
20 | 20 | end |
21 | 21 |
|
| 22 | + describe "POST #validate" do |
| 23 | + let(:item) { create(:item, organization: organization) } |
| 24 | + |
| 25 | + it "returns valid and the confirmation modal body for a valid kit" do |
| 26 | + post validate_kits_url(format: :json), params: { |
| 27 | + kit: { |
| 28 | + name: "A new kit", |
| 29 | + value_in_dollars: "10.10", |
| 30 | + line_items_attributes: {"0": {item_id: item.id, quantity: 5}} |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + expect(response).to be_successful |
| 35 | + json = JSON.parse(response.body) |
| 36 | + expect(json["valid"]).to eq(true) |
| 37 | + expect(json["body"]).to include("A new kit") |
| 38 | + expect(json["body"]).to include("$10.10") |
| 39 | + expect(json["body"]).to include(item.name) |
| 40 | + end |
| 41 | + |
| 42 | + it "returns invalid when the name is blank" do |
| 43 | + post validate_kits_url(format: :json), params: { |
| 44 | + kit: { |
| 45 | + name: "", |
| 46 | + value_in_dollars: "10.10", |
| 47 | + line_items_attributes: {"0": {item_id: item.id, quantity: 5}} |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + expect(response).to be_successful |
| 52 | + json = JSON.parse(response.body) |
| 53 | + expect(json["valid"]).to eq(false) |
| 54 | + expect(json["body"]).to be_nil |
| 55 | + end |
| 56 | + |
| 57 | + it "returns invalid when there are no line items" do |
| 58 | + post validate_kits_url(format: :json), params: { |
| 59 | + kit: {name: "A new kit", value_in_dollars: "10.10"} |
| 60 | + } |
| 61 | + |
| 62 | + expect(response).to be_successful |
| 63 | + json = JSON.parse(response.body) |
| 64 | + expect(json["valid"]).to eq(false) |
| 65 | + end |
| 66 | + |
| 67 | + it "does not persist the kit" do |
| 68 | + expect { |
| 69 | + post validate_kits_url(format: :json), params: { |
| 70 | + kit: { |
| 71 | + name: "A new kit", |
| 72 | + value_in_dollars: "10.10", |
| 73 | + line_items_attributes: {"0": {item_id: item.id, quantity: 5}} |
| 74 | + } |
| 75 | + } |
| 76 | + }.not_to change(Kit, :count) |
| 77 | + end |
| 78 | + end |
| 79 | + |
22 | 80 | describe "GET #index" do |
23 | 81 | before do |
24 | 82 | # this shouldn't be shown |
|
0 commit comments