|
@ -1,9 +1,37 @@ |
|
|
require "./spec_helper" |
|
|
require "./spec_helper" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe SalesBackend do |
|
|
describe SalesBackend do |
|
|
# TODO: Write tests |
|
|
|
|
|
|
|
|
it "can render status" do |
|
|
|
|
|
get "/" |
|
|
|
|
|
String.from_json(Global.response.not_nil!.body).should eq "OK" |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "can add a user able to log in and out" do |
|
|
|
|
|
Dir.mkdir_p Statics.data_path+"user" |
|
|
|
|
|
usr = User.new("dummy@domain.com") |
|
|
|
|
|
usr.password_hash = "mywordismypassword" |
|
|
|
|
|
|
|
|
|
|
|
post "/user", nil, usr.to_json |
|
|
|
|
|
Global.response.not_nil!.status_code.should eq(200) |
|
|
|
|
|
String.from_json(Global.response.not_nil!.body).should eq "OK" |
|
|
|
|
|
|
|
|
|
|
|
post "/login", nil, usr.to_json |
|
|
|
|
|
Global.response.not_nil!.status_code.should eq(200) |
|
|
|
|
|
uuid=UUID.from_json(Global.response.not_nil!.body).not_nil! |
|
|
|
|
|
|
|
|
|
|
|
headers = HTTP::Headers.new |
|
|
|
|
|
headers["user"]=usr.email.to_s |
|
|
|
|
|
headers["api_token"]=uuid.to_s |
|
|
|
|
|
get "/user/", headers |
|
|
|
|
|
Global.response.not_nil!.status_code.should eq(200) |
|
|
|
|
|
|
|
|
|
|
|
usr.tokens = Array(UUID).new |
|
|
|
|
|
usr.tokens.not_nil!.push uuid |
|
|
|
|
|
post "/logout", nil, usr.to_json |
|
|
|
|
|
Global.response.not_nil!.status_code.should eq(200) |
|
|
|
|
|
|
|
|
it "works" do |
|
|
|
|
|
false.should eq(true) |
|
|
|
|
|
|
|
|
get "/user/", headers |
|
|
|
|
|
Global.response.not_nil!.status_code.should eq(403) |
|
|
end |
|
|
end |
|
|
end |
|
|
end |