diff options
Diffstat (limited to 'spec/requests/api/sign_ins/create_spec.cr')
-rw-r--r-- | spec/requests/api/sign_ins/create_spec.cr | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/requests/api/sign_ins/create_spec.cr b/spec/requests/api/sign_ins/create_spec.cr new file mode 100644 index 0000000..520c2df --- /dev/null +++ b/spec/requests/api/sign_ins/create_spec.cr @@ -0,0 +1,33 @@ +require "../../../spec_helper" + +describe Api::SignIns::Create do + it "returns a token" do + UserToken.stub_token("fake-token") do + user = UserFactory.create + + response = ApiClient.exec(Api::SignIns::Create, user: valid_params(user)) + + response.should send_json(200, token: "fake-token") + end + end + + it "returns an error if credentials are invalid" do + user = UserFactory.create + invalid_params = valid_params(user).merge(password: "incorrect") + + response = ApiClient.exec(Api::SignIns::Create, user: invalid_params) + + response.should send_json( + 400, + param: "password", + details: "password is wrong" + ) + end +end + +private def valid_params(user : User) + { + email: user.email, + password: "password", + } +end |