|
1 | 1 | require "swagger_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe "sessions API", type: :request do |
| 4 | + let(:casa_org) { create(:casa_org) } |
| 5 | + let(:volunteer) { create(:volunteer, casa_org: casa_org) } |
| 6 | + |
4 | 7 | path "/api/v1/users/sign_in" do |
5 | 8 | post "Signs in a user" do |
6 | 9 | tags "Sessions" |
|
15 | 18 | required: %w[email password] |
16 | 19 | } |
17 | 20 |
|
18 | | - let(:casa_org) { create(:casa_org) } |
19 | | - let(:volunteer) { create(:volunteer, casa_org: casa_org) } |
20 | | - |
21 | 21 | response "201", "user signed in" do |
22 | 22 | let(:user) { {email: volunteer.email, password: volunteer.password} } |
23 | 23 | schema "$ref" => "#/components/schemas/login_success" |
|
41 | 41 | end |
42 | 42 | end |
43 | 43 | end |
| 44 | + |
| 45 | + path "/api/v1/users/sign_out" do |
| 46 | + delete "Signs out a user" do |
| 47 | + tags "Sessions" |
| 48 | + produces "application/json" |
| 49 | + parameter name: :authorization, in: :header, type: :string, required: true |
| 50 | + |
| 51 | + let(:api_token) { create(:api_credential, user: volunteer).return_new_api_token![:api_token] } |
| 52 | + |
| 53 | + response "200", "user signed out" do |
| 54 | + let(:authorization) { "Bearer #{api_token}" } |
| 55 | + schema "$ref" => "#/components/schemas/sign_out" |
| 56 | + run_test! do |response| |
| 57 | + expect(response.content_type).to eq("application/json; charset=utf-8") |
| 58 | + expect(response.body).to eq({message: "Signed out successfully."}.to_json) |
| 59 | + expect(response.status).to eq(200) |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + response "401", "unauthorized" do |
| 64 | + let(:authorization) { "Bearer foo" } |
| 65 | + schema "$ref" => "#/components/schemas/sign_out" |
| 66 | + run_test! do |response| |
| 67 | + expect(response.content_type).to eq("application/json; charset=utf-8") |
| 68 | + expect(response.body).to eq({message: "An error occured when signing out."}.to_json) |
| 69 | + expect(response.status).to eq(401) |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | + end |
44 | 74 | end |
0 commit comments