summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMattia Roccoberton <mattiaroccoberton@nebulab.it>2021-02-12 12:37:03 +0100
committerAlessandro Desantis <desa.alessandro@gmail.com>2021-03-28 10:25:46 +0200
commit5f14a24c9e9c1a701077d3ac56a632583e51742b (patch)
tree374da57b7bb93d14f50fc5bf14f39d334533c46c /spec
parent6cbd8887c4df74e4e3a010c34b706156b16e8211 (diff)
Add a subscription create endpoint
Mostly the same as update endpoint.
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/v1/subscriptions_spec.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/requests/api/v1/subscriptions_spec.rb b/spec/requests/api/v1/subscriptions_spec.rb
index 6807c67..3031f14 100644
--- a/spec/requests/api/v1/subscriptions_spec.rb
+++ b/spec/requests/api/v1/subscriptions_spec.rb
@@ -3,6 +3,40 @@
RSpec.describe '/api/v1/subscriptions' do
include SolidusSubscriptions::Engine.routes.url_helpers
+ describe 'POST /' do
+ context 'with valid params' do
+ it 'creates the subscription and responds with 200 OK' do
+ user = create(:user, &:generate_spree_api_key!)
+
+ expect do
+ post(
+ api_v1_subscriptions_path,
+ params: { subscription: { interval_length: 11 } },
+ headers: { 'Authorization' => "Bearer #{user.spree_api_key}" },
+ )
+ end.to change(SolidusSubscriptions::Subscription, :count).from(0).to(1)
+
+ expect(response.status).to eq(200)
+ end
+ end
+
+ context 'with invalid params' do
+ it "doesn't create the subscription and responds with 422 Unprocessable Entity" do
+ user = create(:user, &:generate_spree_api_key!)
+
+ expect do
+ post(
+ api_v1_subscriptions_path,
+ params: { subscription: { interval_length: -1 } },
+ headers: { 'Authorization' => "Bearer #{user.spree_api_key}" },
+ )
+ end.not_to change(SolidusSubscriptions::Subscription, :count)
+
+ expect(response.status).to eq(422)
+ end
+ end
+ end
+
describe 'PATCH /:id' do
context 'when the subscription belongs to the user' do
context 'with valid params' do