Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # frozen_string_literal: true
- require "swagger_helper"
- require "devise/jwt/test_helpers"
- describe "Shop API authorization" do
- before :all do
- @password = SecureRandom.base64(20)
- @phone = Faker::PhoneNumber.cell_phone
- @user = FactoryBot.create(:user, phone: @phone, password: @password)
- end
- path "/login" do
- post "user authorization" do
- tags "Authorization"
- parameter name: :body, in: :body, schema: {
- required: [:user],
- type: :object,
- properties: {
- user: {
- type: :object,
- required: [:login, :password],
- properties: {
- login: { type: :string },
- password: { type: :string, format: :password }
- }
- }
- }
- }
- response "201", "success authorization" do
- schema "$ref" => "#/definitions/DefaultSuccessResponse"
- it "returns a 201 Created status" do
- post "/v1/login", params: { user: { login: @phone, password: @password } }
- expect(response).to have_http_status(201)
- end
- end
- response "401", "failed to login, wrong login or password" do
- schema "$ref" => "#/definitions/DefaultErrorResponse"
- it "returns a 401 wrong password" do
- post "/v1/login", params: { user: { login: @user.phone, password: "Wrong Password" } }
- expect(response).to have_http_status(401)
- end
- end
- end
- end
- path "/logout" do
- post "user logout" do
- tags "Authorization"
- security [ bearerAuth: [] ]
- response "204", "success logout" do
- schema "$ref" => "#/definitions/DefaultSuccessResponse"
- it "returns a 204 and logout" do
- headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
- auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
- post "/v1/logout", headers: auth_headers
- expect(response).to have_http_status(204)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement