Advertisement
madrahimov

Untitled

Nov 16th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. require "swagger_helper"
  4. require "devise/jwt/test_helpers"
  5.  
  6. describe "Shop API authorization" do
  7.  
  8. before :all do
  9. @password = SecureRandom.base64(20)
  10. @phone = Faker::PhoneNumber.cell_phone
  11. @user = FactoryBot.create(:user, phone: @phone, password: @password)
  12. end
  13.  
  14. path "/login" do
  15. post "user authorization" do
  16. tags "Authorization"
  17. parameter name: :body, in: :body, schema: {
  18. required: [:user],
  19. type: :object,
  20. properties: {
  21. user: {
  22. type: :object,
  23. required: [:login, :password],
  24. properties: {
  25. login: { type: :string },
  26. password: { type: :string, format: :password }
  27. }
  28. }
  29. }
  30. }
  31.  
  32. response "201", "success authorization" do
  33. schema "$ref" => "#/definitions/DefaultSuccessResponse"
  34.  
  35. it "returns a 201 Created status" do
  36. post "/v1/login", params: { user: { login: @phone, password: @password } }
  37. expect(response).to have_http_status(201)
  38. end
  39. end
  40.  
  41. response "401", "failed to login, wrong login or password" do
  42. schema "$ref" => "#/definitions/DefaultErrorResponse"
  43. it "returns a 401 wrong password" do
  44. post "/v1/login", params: { user: { login: @user.phone, password: "Wrong Password" } }
  45. expect(response).to have_http_status(401)
  46. end
  47. end
  48.  
  49. end
  50. end
  51.  
  52.  
  53. path "/logout" do
  54. post "user logout" do
  55. tags "Authorization"
  56. security [ bearerAuth: [] ]
  57.  
  58. response "204", "success logout" do
  59. schema "$ref" => "#/definitions/DefaultSuccessResponse"
  60.  
  61. it "returns a 204 and logout" do
  62.  
  63. headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  64. auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
  65.  
  66. post "/v1/logout", headers: auth_headers
  67.  
  68. expect(response).to have_http_status(204)
  69. end
  70. end
  71. end
  72. end
  73.  
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement