require_relative "./base" class UserPexSystemTest < LifePexTest def setup @fixture ||= FixtureReader.new # should be in startup @fixture.apply! "user_base" @fixture.apply! "pex_base" end def cleanup @fixture.cleanup! end def test_user_pex_counter login_as assert last_response.ok? api_get "/api/user-pex/v1/pexs/1/amount/by-date/2021-01-01" assert last_response.ok? assert_equal 0, api_reponse_body["count"], "No user pex counted yet" api_post "/api/user-pex/v1/pexs/1/validation", { date: "2021-01-01" } assert last_response.ok? assert_equal "2021-01-01", api_reponse_body.dig("user_pex", "created_at") assert_equal 1, api_reponse_body.dig("user_pex", "pex_id") assert_equal 1, api_reponse_body.dig("user_pex", "user_id") api_get "/api/user-pex/v1/pexs/1/amount/by-date/2021-01-01" assert last_response.ok? assert_equal 1, api_reponse_body["count"], "One use pex is added" api_delete "/api/user-pex/v1/pexs/1/validation", { date: "2021-01-01" } assert last_response.ok? api_get "/api/user-pex/v1/pexs/1/amount/by-date/2021-01-01" assert last_response.ok? assert_equal 0, api_reponse_body["count"], "No user pex remaining" api_delete "/api/user-pex/v1/pexs/1/validation", { date: "2021-01-01" } assert_client_error end end