Implementation of a generic backend of eshop in Crystal
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
  1. require "./spec_helper"
  2. describe SalesBackend do
  3. it "can render status" do
  4. get "/"
  5. String.from_json(Global.response.not_nil!.body).should eq "OK"
  6. end
  7. it "can add a user able to log in and out" do
  8. Dir.mkdir_p Statics.data_path+"user"
  9. usr = User.new("dummy@domain.com")
  10. usr.password_hash = "mywordismypassword"
  11. post "/user", nil, usr.to_json
  12. Global.response.not_nil!.status_code.should eq(200)
  13. String.from_json(Global.response.not_nil!.body).should eq "OK"
  14. post "/login", nil, usr.to_json
  15. Global.response.not_nil!.status_code.should eq(200)
  16. uuid=UUID.from_json(Global.response.not_nil!.body).not_nil!
  17. headers = HTTP::Headers.new
  18. headers["user"]=usr.email.to_s
  19. headers["api_token"]=uuid.to_s
  20. get "/user/", headers
  21. Global.response.not_nil!.status_code.should eq(200)
  22. usr.tokens = Array(UUID).new
  23. usr.tokens.not_nil!.push uuid
  24. post "/logout", nil, usr.to_json
  25. Global.response.not_nil!.status_code.should eq(200)
  26. get "/user/", headers
  27. Global.response.not_nil!.status_code.should eq(403)
  28. end
  29. end