|
| 1 | +<?php |
| 2 | + |
| 3 | +use App\Models\User; |
| 4 | +use App\Modules\Core\Models\Tenant; |
| 5 | +use App\Modules\HR\Models\JobOfferLetter; |
| 6 | +use Database\Seeders\RolePermissionSeeder; |
| 7 | + |
| 8 | +beforeEach(function () { |
| 9 | + $this->seed(RolePermissionSeeder::class); |
| 10 | + $this->tenant = Tenant::create(['name' => 'OfferCorp', 'slug' => 'offer-corp-' . uniqid()]); |
| 11 | + $this->admin = User::factory()->create(['tenant_id' => $this->tenant->id]); |
| 12 | + $this->admin->assignRole('super-admin'); |
| 13 | + $this->actingAs($this->admin); |
| 14 | + app()->instance('tenant', $this->tenant); |
| 15 | +}); |
| 16 | + |
| 17 | +function makeOfferLetter(array $attrs = []): JobOfferLetter |
| 18 | +{ |
| 19 | + return JobOfferLetter::create([ |
| 20 | + 'tenant_id' => test()->tenant->id, |
| 21 | + 'candidate_name' => 'Jane Doe', |
| 22 | + 'candidate_email' => 'jane.' . uniqid() . '@example.com', |
| 23 | + 'position_title' => 'Software Engineer', |
| 24 | + 'created_by' => test()->admin->id, |
| 25 | + ...$attrs, |
| 26 | + ]); |
| 27 | +} |
| 28 | + |
| 29 | +it('index requires authentication', function () { |
| 30 | + $this->post('/logout'); |
| 31 | + $this->get('/hr/job-offers')->assertRedirect('/login'); |
| 32 | +}); |
| 33 | + |
| 34 | +it('admin can list job offers', function () { |
| 35 | + makeOfferLetter(); |
| 36 | + $this->get('/hr/job-offers')->assertOk(); |
| 37 | +}); |
| 38 | + |
| 39 | +it('store creates a job offer letter', function () { |
| 40 | + $this->post('/hr/job-offers', [ |
| 41 | + 'candidate_name' => 'John Smith', |
| 42 | + 'candidate_email' => 'john@example.com', |
| 43 | + 'position_title' => 'Product Manager', |
| 44 | + 'offered_salary' => 80000, |
| 45 | + ])->assertRedirect(); |
| 46 | + |
| 47 | + expect(JobOfferLetter::where('candidate_email', 'john@example.com')->exists())->toBeTrue(); |
| 48 | +}); |
| 49 | + |
| 50 | +it('store validates required fields', function () { |
| 51 | + $this->postJson('/hr/job-offers', [])->assertStatus(422)->assertJsonValidationErrors(['candidate_name', 'candidate_email', 'position_title']); |
| 52 | +}); |
| 53 | + |
| 54 | +it('show displays a job offer', function () { |
| 55 | + $offer = makeOfferLetter(); |
| 56 | + $this->get("/hr/job-offers/{$offer->id}")->assertOk(); |
| 57 | +}); |
| 58 | + |
| 59 | +it('send transitions status to sent', function () { |
| 60 | + $offer = makeOfferLetter(); |
| 61 | + expect($offer->status)->toBe('draft'); |
| 62 | + |
| 63 | + $this->post("/hr/job-offers/{$offer->id}/send")->assertRedirect(); |
| 64 | + |
| 65 | + $offer->refresh(); |
| 66 | + expect($offer->status)->toBe('sent'); |
| 67 | + expect($offer->sent_at)->not->toBeNull(); |
| 68 | + expect($offer->is_pending)->toBeTrue(); |
| 69 | +}); |
| 70 | + |
| 71 | +it('accept transitions status to accepted', function () { |
| 72 | + $offer = makeOfferLetter(['status' => 'sent']); |
| 73 | + $this->post("/hr/job-offers/{$offer->id}/accept")->assertRedirect(); |
| 74 | + $offer->refresh(); |
| 75 | + expect($offer->status)->toBe('accepted'); |
| 76 | + expect($offer->responded_at)->not->toBeNull(); |
| 77 | +}); |
| 78 | + |
| 79 | +it('decline transitions status to declined', function () { |
| 80 | + $offer = makeOfferLetter(['status' => 'sent']); |
| 81 | + $this->post("/hr/job-offers/{$offer->id}/decline")->assertRedirect(); |
| 82 | + $offer->refresh(); |
| 83 | + expect($offer->status)->toBe('declined'); |
| 84 | +}); |
| 85 | + |
| 86 | +it('is_expired accessor returns true for past expiry non-accepted offer', function () { |
| 87 | + $offer = makeOfferLetter([ |
| 88 | + 'status' => 'sent', |
| 89 | + 'offer_expiry_date' => now()->subDay()->toDateString(), |
| 90 | + ]); |
| 91 | + expect($offer->is_expired)->toBeTrue(); |
| 92 | +}); |
| 93 | + |
| 94 | +it('destroy soft-deletes the offer', function () { |
| 95 | + $offer = makeOfferLetter(); |
| 96 | + $this->delete("/hr/job-offers/{$offer->id}")->assertRedirect(); |
| 97 | + expect(JobOfferLetter::find($offer->id))->toBeNull(); |
| 98 | + expect(JobOfferLetter::withTrashed()->find($offer->id))->not->toBeNull(); |
| 99 | +}); |
0 commit comments