-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae1a9c9
commit ec034cd
Showing
1 changed file
with
0 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +0,0 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe AttendanceRequest, type: :model do | ||
describe 'attendance request approval' do | ||
let(:staff_role) { Role.create(name: 'Staff', code: 'staff') } | ||
let(:supervisor_role) { Role.create(name: 'Supervisor', code: 'supervisor') } | ||
|
||
let(:organization) { Organization.create(name: 'Sample Org', description: 'Test Organization') } | ||
let(:department) { Department.create(name: 'Sample Department', description: 'Test Department', organization: organization) } | ||
|
||
let(:staff_user) do | ||
User.create( | ||
email: '[email protected]', | ||
password: 'PaSSw0RD123', | ||
role: staff_role, | ||
organization: organization, | ||
department: department | ||
) | ||
end | ||
|
||
let(:supervisor_user) do | ||
User.create( | ||
email: '[email protected]', | ||
password: 'PaSSw0RD123', | ||
role: supervisor_role, | ||
organization: organization, | ||
department: department | ||
) | ||
end | ||
|
||
it 'allows a staff user to request attendance and a supervisor to approve it' do | ||
attendance_request = AttendanceRequest.new( | ||
requested_by: staff_user, | ||
approved_by: nil, # Initially, approved_by is nil | ||
notes: 'Test notes', | ||
requested_at: Date.today, | ||
live_location: 'Sample Location', | ||
selfie_image: 'Sample Image', | ||
attendance_status: AttendanceStatus.new(name: 'Pending', code: 'pending') | ||
) | ||
|
||
expect(attendance_request.valid?).to be true | ||
attendance_request.save | ||
|
||
# Ensure the request is initially in a "Pending" status | ||
expect(attendance_request.attendance_status.name).to eq('Pending') | ||
|
||
# Now, simulate the supervisor approving the request | ||
attendance_request.approved_by = supervisor_user | ||
|
||
# Update the status in the database | ||
attendance_request.update(attendance_status: AttendanceStatus.find_by(name: 'Approved')) | ||
|
||
# Reload the record from the database to reflect the changes | ||
attendance_request.reload | ||
|
||
# Verify that the request is approved and the status is updated to "Approved" | ||
expect(attendance_request.approved_by).to eq(supervisor_user) | ||
expect(attendance_request.attendance_status.name).to eq('Approved') | ||
end | ||
end | ||
end | ||