Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit acd5be6

Browse files
committed
Added tests
1 parent 92cae43 commit acd5be6

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

src/ApiService/ApiService/OneFuzzTypes/Model.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -899,30 +899,14 @@ public JobConfig Truncate(int maxLength) {
899899
}
900900
}
901901

902-
[JsonConverter(typeof(IJobTaskInfoConverter))]
902+
[JsonDerivedType(typeof(Task), typeDiscriminator: "Task")]
903+
[JsonDerivedType(typeof(JobTaskInfo), typeDiscriminator: "JobTaskInfo")]
903904
public interface IJobTaskInfo {
904905
Guid TaskId { get; }
905906
TaskType Type { get; }
906907
TaskState State { get; }
907-
908908
}
909909

910-
public class IJobTaskInfoConverter : JsonConverter<IJobTaskInfo> {
911-
public override IJobTaskInfo Read(
912-
ref Utf8JsonReader reader,
913-
Type typeToConvert,
914-
JsonSerializerOptions options) {
915-
throw new NotImplementedException();
916-
}
917-
918-
public override void Write(
919-
Utf8JsonWriter writer,
920-
IJobTaskInfo value,
921-
JsonSerializerOptions options) {
922-
var type = value.GetType();
923-
JsonSerializer.Serialize(writer, value, type, options);
924-
}
925-
}
926910
public record JobTaskInfo(
927911
Guid TaskId,
928912
TaskType Type,

src/ApiService/IntegrationTests/JobsTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,55 @@ public async Async.Task Post_CreatesJob_AndContainer() {
175175
var metadata = Assert.Single(container.Value);
176176
Assert.Equal(new KeyValuePair<string, string>("container_type", "logs"), metadata);
177177
}
178+
179+
180+
[Fact]
181+
public async Async.Task Get_CanFindSpecificJobWithTaskInfo() {
182+
183+
var taskConfig = new TaskConfig(_jobId, new List<Guid>(), new TaskDetails(TaskType.Coverage, 60));
184+
var task = new Task(_jobId, Guid.NewGuid(), TaskState.Running, Os.Windows, taskConfig);
185+
186+
await Context.InsertAll(
187+
new Job(_jobId, JobState.Stopped, _config, null), task);
188+
189+
var func = new Jobs(Context, LoggerProvider.CreateLogger<Jobs>());
190+
191+
var ctx = new TestFunctionContext();
192+
var result = await func.Run(TestHttpRequestData.FromJson("GET", new JobSearch(JobId: _jobId, WithTasks: false)), ctx);
193+
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
194+
195+
var response = BodyAs<JobResponse>(result);
196+
Assert.Equal(_jobId, response.JobId);
197+
Assert.NotNull(response.TaskInfo);
198+
var returnedTasks = response.TaskInfo.OfType<JobTaskInfo>().ToList();
199+
Assert.NotEmpty(returnedTasks);
200+
Assert.Equal(task.TaskId, returnedTasks[0].TaskId);
201+
Assert.Equal(task.State, returnedTasks[0].State);
202+
Assert.Equal(task.Config.Task.Type, returnedTasks[0].Type);
203+
}
204+
205+
[Fact]
206+
public async Async.Task Get_CanFindSpecificJobWithFullTask() {
207+
var taskConfig = new TaskConfig(_jobId, new List<Guid>(), new TaskDetails(TaskType.Coverage, 60));
208+
var task = new Task(_jobId, Guid.NewGuid(), TaskState.Running, Os.Windows, taskConfig);
209+
210+
await Context.InsertAll(
211+
new Job(_jobId, JobState.Stopped, _config, null), task);
212+
213+
var func = new Jobs(Context, LoggerProvider.CreateLogger<Jobs>());
214+
215+
var ctx = new TestFunctionContext();
216+
var result = await func.Run(TestHttpRequestData.FromJson("GET", new JobSearch(JobId: _jobId, WithTasks: true)), ctx);
217+
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
218+
219+
var response = BodyAs<JobResponse>(result);
220+
Assert.Equal(_jobId, response.JobId);
221+
Assert.NotNull(response.TaskInfo);
222+
var returnedTasks = response.TaskInfo.OfType<Task>().ToList();
223+
Assert.NotEmpty(returnedTasks);
224+
Assert.Equal(task.TaskId, returnedTasks[0].TaskId);
225+
Assert.Equal(task.State, returnedTasks[0].State);
226+
Assert.Equal(task.Config.Task.Type, returnedTasks[0].Type);
227+
228+
}
178229
}

0 commit comments

Comments
 (0)