require "rails_helper" # Automatically generated by the orthodox gem (https://github.com/katanacode/orthodox) # (c) Copyright 2019 Katana Code Ltd. All Rights Reserved. RSpec.describe TfaSession, type: :model do let!(:<%= singular_name %>) { create(:<%= singular_name %>) } before do <%= singular_name %>.create_otp_credential! end describe "#valid?" do subject { TfaSession.new(record: <%= singular_name %>) } context "when otp correct" do before do subject.otp = <%= singular_name %>.otp_credential.send(:current_otp) end it { is_expected.to be_valid } end context "when otp incorrect" do before do subject.otp = "12345" end it { is_expected.to be_invalid } end context "when recovery code correct" do before do subject.recovery_code = <%= singular_name %>.otp_credential.recovery_codes.sample end it { is_expected.to be_valid } end context "when recovery code incorrect" do before do subject.recovery_code = "abcd-efgh" end it { is_expected.to be_invalid } end end describe "#otp?" do context "when present" do before do subject.otp = "12345" end it "is expected to be truthy" do expect(subject.otp?).to be_truthy end end context "when blank" do before do subject.otp = nil end it "is expected to be falsey" do expect(subject.otp?).to be_falsey end end end describe "#recovery_code?" do context "when present" do before do subject.recovery_code = "abcd-defg" end it "is expected to be truthy" do expect(subject.recovery_code?).to be_truthy end end context "when blank" do before do subject.recovery_code = nil end it "is expected to be falsey" do expect(subject.recovery_code?).to be_falsey end end end end