|
| 1 | +using Bogus; |
| 2 | +using Bogus.DataSets; |
| 3 | +using Helpdesk.Api.Incidents; |
| 4 | +using Helpdesk.Api.Incidents.GetIncidentDetails; |
| 5 | +using Ogooreck.API; |
| 6 | +using static Ogooreck.API.ApiSpecification; |
| 7 | + |
| 8 | +namespace Helpdesk.Api.Tests.Incidents.Fixtures; |
| 9 | + |
| 10 | +public static class Scenarios |
| 11 | +{ |
| 12 | + private static readonly Faker faker = new(); |
| 13 | + private static readonly Lorem loremIpsum = new(); |
| 14 | + |
| 15 | + public static async Task<IncidentDetails> LoggedIncident( |
| 16 | + this ApiSpecification<Program> api |
| 17 | + ) |
| 18 | + { |
| 19 | + var customerId = Guid.NewGuid(); |
| 20 | + |
| 21 | + var contact = new Contact( |
| 22 | + faker.PickRandom<ContactChannel>(), |
| 23 | + faker.Name.FirstName(), |
| 24 | + faker.Name.LastName(), |
| 25 | + faker.Internet.Email(), |
| 26 | + faker.Phone.PhoneNumber() |
| 27 | + ); |
| 28 | + var incidentDescription = loremIpsum.Sentence(); |
| 29 | + |
| 30 | + var response = await api.Scenario( |
| 31 | + api.LogIncident(customerId, contact, incidentDescription), |
| 32 | + r => api.GetIncidentDetails(r.GetCreatedId<Guid>()) |
| 33 | + ); |
| 34 | + |
| 35 | + return await response.GetResultFromJson<IncidentDetails>(); |
| 36 | + } |
| 37 | + |
| 38 | + public static async Task<IncidentDetails> ResolvedIncident( |
| 39 | + this ApiSpecification<Program> api |
| 40 | + ) |
| 41 | + { |
| 42 | + var agentId = Guid.NewGuid(); |
| 43 | + var resolvedType = faker.PickRandom<ResolutionType>(); |
| 44 | + var incident = await api.LoggedIncident(); |
| 45 | + |
| 46 | + var response = await api.Scenario( |
| 47 | + api.ResolveIncident(incident.Id, agentId, resolvedType), |
| 48 | + _ => api.GetIncidentDetails(incident.Id) |
| 49 | + ); |
| 50 | + |
| 51 | + return await response.GetResultFromJson<IncidentDetails>(); |
| 52 | + } |
| 53 | + |
| 54 | + public static async Task<IncidentDetails> AcknowledgedIncident( |
| 55 | + this ApiSpecification<Program> api |
| 56 | + ) |
| 57 | + { |
| 58 | + var incident = await api.ResolvedIncident(); |
| 59 | + |
| 60 | + var response = await api.Scenario( |
| 61 | + api.AcknowledgeIncident(incident.Id, incident.CustomerId), |
| 62 | + _ => api.GetIncidentDetails(incident.Id) |
| 63 | + ); |
| 64 | + |
| 65 | + return await response.GetResultFromJson<IncidentDetails>(); |
| 66 | + } |
| 67 | + |
| 68 | + private static Task<HttpResponseMessage> LogIncident( |
| 69 | + this ApiSpecification<Program> api, |
| 70 | + Guid customerId, |
| 71 | + Contact contact, |
| 72 | + string incidentDescription |
| 73 | + ) => |
| 74 | + api.Given( |
| 75 | + URI($"api/customers/{customerId}/incidents/"), |
| 76 | + BODY(new LogIncidentRequest(contact, incidentDescription)) |
| 77 | + ) |
| 78 | + .When(POST) |
| 79 | + .Then(CREATED_WITH_DEFAULT_HEADERS(locationHeaderPrefix: "/api/incidents/")); |
| 80 | + |
| 81 | + private static Task<HttpResponseMessage> ResolveIncident<T>( |
| 82 | + this ApiSpecification<T> api, |
| 83 | + Guid incidentId, |
| 84 | + Guid agentId, |
| 85 | + ResolutionType resolutionType |
| 86 | + ) where T : class => |
| 87 | + api.Given( |
| 88 | + URI($"/api/agents/{agentId}/incidents/{incidentId}/resolve"), |
| 89 | + BODY(new ResolveIncidentRequest(resolutionType)), |
| 90 | + HEADERS(IF_MATCH(1)) |
| 91 | + ) |
| 92 | + .When(POST) |
| 93 | + .Then(OK); |
| 94 | + |
| 95 | + private static Task<HttpResponseMessage> AcknowledgeIncident<T>( |
| 96 | + this ApiSpecification<T> api, |
| 97 | + Guid incidentId, |
| 98 | + Guid customerId |
| 99 | + ) where T : class => |
| 100 | + api.Given( |
| 101 | + URI($"/api/customers/{customerId}/incidents/{incidentId}/acknowledge"), |
| 102 | + HEADERS(IF_MATCH(2)) |
| 103 | + ) |
| 104 | + .When(POST) |
| 105 | + .Then(OK); |
| 106 | + |
| 107 | + private static Task<HttpResponseMessage> GetIncidentDetails( |
| 108 | + this ApiSpecification<Program> api, |
| 109 | + Guid incidentId |
| 110 | + ) => |
| 111 | + api.Given(URI($"/api/incidents/{incidentId}")) |
| 112 | + .When(GET) |
| 113 | + .Then(OK); |
| 114 | +} |
0 commit comments