|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "test_helper" |
| 4 | + |
| 5 | +class VersionEndpointTest < ActionDispatch::IntegrationTest |
| 6 | + def test_anonymous_version_endpoint |
| 7 | + get "/api/v1/version.json" |
| 8 | + assert_response :success |
| 9 | + assert_equal Version.current.to_s, JSON.parse(@response.body)["application_version"] |
| 10 | + assert_equal Apipie.configuration.default_version, JSON.parse(@response.body)["api_version"] |
| 11 | + assert_equal "oss", JSON.parse(@response.body)["edition"] |
| 12 | + |
| 13 | + get "/api/v1/version" |
| 14 | + assert_response :success |
| 15 | + assert_equal Version.current.to_s, JSON.parse(@response.body)["application_version"] |
| 16 | + assert_equal Apipie.configuration.default_version, JSON.parse(@response.body)["api_version"] |
| 17 | + assert_equal "oss", JSON.parse(@response.body)["edition"] |
| 18 | + end |
| 19 | + |
| 20 | + def test_authenticated_version_endpoint |
| 21 | + @user_one = users(:one) |
| 22 | + sign_in @user_one |
| 23 | + |
| 24 | + get "/api/v1/version.json", |
| 25 | + headers: { |
| 26 | + "Accept" => "application/json", |
| 27 | + "Authorization" => "Bearer #{@user_one.authentication_token}" |
| 28 | + } |
| 29 | + |
| 30 | + assert_response :success |
| 31 | + assert_equal Version.current.to_s, JSON.parse(@response.body)["application_version"] |
| 32 | + assert_equal Apipie.configuration.default_version, JSON.parse(@response.body)["api_version"] |
| 33 | + assert_equal "oss", JSON.parse(@response.body)["edition"] |
| 34 | + |
| 35 | + @user_one = users(:one) |
| 36 | + sign_in @user_one |
| 37 | + |
| 38 | + get "/api/v1/version", |
| 39 | + headers: { |
| 40 | + "Accept" => "application/json", |
| 41 | + "Authorization" => "Bearer #{@user_one.authentication_token}" |
| 42 | + } |
| 43 | + |
| 44 | + assert_response :success |
| 45 | + assert_equal Version.current.to_s, JSON.parse(@response.body)["application_version"] |
| 46 | + assert_equal Apipie.configuration.default_version, JSON.parse(@response.body)["api_version"] |
| 47 | + assert_equal "oss", JSON.parse(@response.body)["edition"] |
| 48 | + end |
| 49 | +end |
0 commit comments