TripInvitationRepositoryTests.cs
1,251 bytes
| 1 | using App.DAL.EF.Repositories; |
|---|---|
| 2 | using App.Domain; |
| 3 | using FluentAssertions; |
| 4 | |
| 5 | namespace App.Tests.DAL; |
| 6 | |
| 7 | public class TripInvitationRepositoryTests : RepositoryTestBase |
| 8 | { |
| 9 | [Fact] |
| 10 | public async Task GetByTokenAsync_WhenTokenExists_ReturnsInvitation() |
| 11 | { |
| 12 | // Arrange |
| 13 | var (_, user, trip) = await SeedTripAsync(); |
| 14 | var token = "test-invite-token-abc123"; |
| 15 | Context.TripInvitations.Add(new TripInvitation |
| 16 | { |
| 17 | TripId = trip.Id, |
| 18 | InvitedByUserId = user.Id, |
| 19 | Token = token, |
| 20 | Status = EInvitationStatus.Pending, |
| 21 | ExpiresAt = DateTime.UtcNow.AddDays(7) |
| 22 | }); |
| 23 | await Context.SaveChangesAsync(); |
| 24 | var repo = new TripInvitationRepository(Context); |
| 25 | |
| 26 | // Act |
| 27 | var result = await repo.GetByTokenAsync(token); |
| 28 | |
| 29 | // Assert |
| 30 | result.Should().NotBeNull(); |
| 31 | result!.Token.Should().Be(token); |
| 32 | result.Status.Should().Be(EInvitationStatus.Pending); |
| 33 | } |
| 34 | |
| 35 | [Fact] |
| 36 | public async Task GetByTokenAsync_WhenTokenDoesNotExist_ReturnsNull() |
| 37 | { |
| 38 | var repo = new TripInvitationRepository(Context); |
| 39 | |
| 40 | var result = await repo.GetByTokenAsync("nonexistent-token"); |
| 41 | |
| 42 | result.Should().BeNull(); |
| 43 | } |
| 44 | } |
| 45 | |