require 'spec_helper' describe Lifen::User do describe ':create' do context 'missing field' do let(:user) { Lifen::User.new() } it 'raises an error' do expect{ VCR.use_cassette "users/create/missing_fields" do user.create! end }.to raise_error(Lifen::Error) end end context 'invalid secret key' do let(:user) { Lifen::User.new(email: "invalid-key-email@test.tld") } before do Lifen.configure do |config| config.secret_key = "invalid-secret-key" end end it 'raises an error' do expect{ VCR.use_cassette "users/create/invalid_token" do user.create! end }.to raise_error(Lifen::InvalidSecretTokenError) end end context 'exisiting user' do let(:user) { Lifen::User.new(email: "existing-user@domain.tld") } it 'creates the user' do expect{ VCR.use_cassette "users/create/existing_user" do user.create! end }.to raise_error(Lifen::UserAlreadyExistingError) end end context 'valid attributes' do let(:user) { Lifen::User.new(email: "valid-email-spec@domain.tld") } it 'creates the user' do VCR.use_cassette "users/create/valid_attributes" do user.create! end expect(user.token).to_not be_nil expect(user.uuid).to_not be_nil end end end describe ':refresh_token' do context 'invalid user uuid' do let(:user) { Lifen::User.new(uuid: "invalid-user-uuid") } it 'raises an error' do expect{ VCR.use_cassette "users/refresh/invalid_user_uuid" do user.refresh_token end }.to raise_error(Lifen::Error) end end context 'valid user uuid' do let(:user) { Lifen::User.new(uuid: "valid_uuid") } it 'raises an error' do previous_token = user.token VCR.use_cassette "users/refresh/valid_user_uuid" do user.refresh_token end expect(user.token).to_not be_nil expect(user.token).to_not eq previous_token end end end end