aboutsummaryrefslogtreecommitdiff
path: root/spec/requests/api/sign_ins/create_spec.cr
blob: 520c2dff57cab75fba8eee2ffabfb2bef8515393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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