Class: CmQuiz::Review::LoginUser

Inherits:
BaseReview show all
Defined in:
lib/cm_quiz/review/login_user.rb

Instance Attribute Summary

Attributes inherited from BaseReview

#options, #path, #verb

Instance Method Summary collapse

Methods inherited from BaseReview

#build_test_result, #perform, #test_request

Methods included from CmQuiz::ReviewHelper

#be, #be_nil, #be_within, #eq, #expect

Constructor Details

#initialize(project_api:) ⇒ LoginUser

Returns a new instance of LoginUser.



6
7
8
9
10
# File 'lib/cm_quiz/review/login_user.rb', line 6

def initialize(project_api:)
  @project_api = project_api
  @verb = :post
  @path = '/access-tokens'
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cm_quiz/review/login_user.rb', line 12

def run
  name = "codementor-test-#{SecureRandom.hex(5)}"
  email = "#{name}@codementor.io"
  password = "pAssw0rd!"
  Factory::User.new({
    project_api: @project_api,
    name: name,
    email: email,
    password: password
  }).create

  @options = build_options(email: email, password: password)
  res = send_request(@options)
  payload = JSON.parse(res.body)

  expect(payload['jwt'].class).to eq(String), '`jwt` should be string'
  expect(payload['refresh_token'].class).to eq(String), '`refresh_token` should be string'
rescue => e
  build_test_result(self.class, false, e.message)
end