Run format
This commit is contained in:
@@ -11,7 +11,8 @@ public class MissionControlContext(DbContextOptions<MissionControlContext> optio
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<Mission>()
|
modelBuilder
|
||||||
|
.Entity<Mission>()
|
||||||
.HasMany(mission => mission.MissionLaunches)
|
.HasMany(mission => mission.MissionLaunches)
|
||||||
.WithOne(missionLaunch => missionLaunch.Mission)
|
.WithOne(missionLaunch => missionLaunch.Mission)
|
||||||
.HasForeignKey(missionLaunch => missionLaunch.MissionId)
|
.HasForeignKey(missionLaunch => missionLaunch.MissionId)
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public record MissionResponse
|
|||||||
Description = mission.Description,
|
Description = mission.Description,
|
||||||
Status = mission.Status,
|
Status = mission.Status,
|
||||||
CreatedAt = mission.CreatedAt,
|
CreatedAt = mission.CreatedAt,
|
||||||
MissionLaunches = mission.MissionLaunches.Select(MissionLaunchResponse.FromDomain).ToList(),
|
MissionLaunches = mission
|
||||||
|
.MissionLaunches.Select(MissionLaunchResponse.FromDomain)
|
||||||
|
.ToList(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ public class ListMissions(MissionControlContext dbContext)
|
|||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
var missions = await dbContext.Missions
|
var missions = await dbContext
|
||||||
.AsNoTracking()
|
.Missions.AsNoTracking()
|
||||||
.Include(m => m.MissionLaunches.OrderByDescending(l => l.ScheduledFor))
|
.Include(m => m.MissionLaunches.OrderByDescending(l => l.ScheduledFor))
|
||||||
.OrderByDescending(m => m.CreatedAt)
|
.OrderByDescending(m => m.CreatedAt)
|
||||||
.ToListAsync(ct);
|
.ToListAsync(ct);
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ public class CreateMissionLaunch(MissionControlContext dbContext)
|
|||||||
|
|
||||||
public override async Task HandleAsync(CreateMissionLaunchRequest req, CancellationToken ct)
|
public override async Task HandleAsync(CreateMissionLaunchRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var missionExists = await dbContext.Missions.AnyAsync(mission => mission.Id == req.MissionId, ct);
|
var missionExists = await dbContext.Missions.AnyAsync(
|
||||||
|
mission => mission.Id == req.MissionId,
|
||||||
|
ct
|
||||||
|
);
|
||||||
if (!missionExists)
|
if (!missionExists)
|
||||||
{
|
{
|
||||||
await Send.NotFoundAsync(ct);
|
await Send.NotFoundAsync(ct);
|
||||||
|
|||||||
@@ -1,30 +1,32 @@
|
|||||||
import { MantineProvider } from '@mantine/core';
|
import { MantineProvider } from '@mantine/core';
|
||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import type { MissionLaunch } from '../../api/missionLaunches';
|
||||||
import type { Mission } from '../../api/missions';
|
import type { Mission } from '../../api/missions';
|
||||||
import { MissionsTable } from './MissionsTable';
|
import { MissionsTable } from './MissionsTable';
|
||||||
import type { MissionLaunch } from '../../api/missionLaunches';
|
|
||||||
|
|
||||||
function missionLaunches(): MissionLaunch[] {
|
function missionLaunches(): MissionLaunch[] {
|
||||||
return [{
|
return [
|
||||||
id: 'launch id',
|
{
|
||||||
scheduledFor: '2026-07-07T13:56:00+00:00',
|
id: 'launch id',
|
||||||
status: 'Pending',
|
scheduledFor: '2026-07-07T13:56:00+00:00',
|
||||||
createdAt: '2026-07-07T13:56:00+00:00',
|
status: 'Pending',
|
||||||
}];
|
createdAt: '2026-07-07T13:56:00+00:00',
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMockMissions(withLaunches = false): Mission[] {
|
function getMockMissions(withLaunches = false): Mission[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
id: 'a mission id',
|
id: 'a mission id',
|
||||||
name: 'mission name is here!',
|
name: 'mission name is here!',
|
||||||
description: null,
|
description: null,
|
||||||
status: 'Planned',
|
status: 'Planned',
|
||||||
createdAt: '',
|
createdAt: '',
|
||||||
missionLaunches: withLaunches ? missionLaunches() : [],
|
missionLaunches: withLaunches ? missionLaunches() : [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('MissionsTable', () => {
|
describe('MissionsTable', () => {
|
||||||
@@ -60,9 +62,7 @@ describe('MissionsTable', () => {
|
|||||||
screen.getAllByTestId('row-expand')[0].click();
|
screen.getAllByTestId('row-expand')[0].click();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
screen.queryByText(
|
screen.queryByText('No launches have been created for this mission yet!'),
|
||||||
'No launches have been created for this mission yet!',
|
|
||||||
),
|
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -76,9 +76,7 @@ describe('MissionsTable', () => {
|
|||||||
screen.getAllByTestId('row-expand')[0].click();
|
screen.getAllByTestId('row-expand')[0].click();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
screen.queryByText(
|
screen.queryByText('No launches have been created for this mission yet!'),
|
||||||
'No launches have been created for this mission yet!',
|
|
||||||
),
|
|
||||||
).toBeNull();
|
).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { toReadableDateTime } from "./dateUtils";
|
import { toReadableDateTime } from './dateUtils';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.stubEnv('TZ', 'UTC');
|
vi.stubEnv('TZ', 'UTC');
|
||||||
@@ -14,10 +14,10 @@ describe('dateUtils', () => {
|
|||||||
it('returns invalid date when datetime passed is in incorrect format', () => {
|
it('returns invalid date when datetime passed is in incorrect format', () => {
|
||||||
const date = toReadableDateTime('invalid');
|
const date = toReadableDateTime('invalid');
|
||||||
|
|
||||||
expect(date).toBe("Invalid Date");
|
expect(date).toBe('Invalid Date');
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('returns readable date when datetime passed is in valid format', () => {
|
it('returns readable date when datetime passed is in valid format', () => {
|
||||||
const date = toReadableDateTime('2026-07-27T23:27:22.1976394+00:00');
|
const date = toReadableDateTime('2026-07-27T23:27:22.1976394+00:00');
|
||||||
|
|
||||||
expect(date).toBe('27/07/2026, 23:27:22');
|
expect(date).toBe('27/07/2026, 23:27:22');
|
||||||
|
|||||||
+11
-7
@@ -30,14 +30,18 @@ public class CreateMissionLaunchTests
|
|||||||
{
|
{
|
||||||
var validator = new CreateMissionLaunchRequestValidator();
|
var validator = new CreateMissionLaunchRequestValidator();
|
||||||
|
|
||||||
var result = validator.Validate(new CreateMissionLaunchRequest
|
var result = validator.Validate(
|
||||||
{
|
new CreateMissionLaunchRequest
|
||||||
MissionId = Guid.Empty,
|
{
|
||||||
ScheduledFor = default,
|
MissionId = Guid.Empty,
|
||||||
Status = MissionLaunchStatus.Pending,
|
ScheduledFor = default,
|
||||||
});
|
Status = MissionLaunchStatus.Pending,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
result.IsValid.ShouldBeFalse();
|
result.IsValid.ShouldBeFalse();
|
||||||
result.Errors.ShouldContain(e => e.PropertyName == nameof(CreateMissionLaunchRequest.MissionId));
|
result.Errors.ShouldContain(e =>
|
||||||
|
e.PropertyName == nameof(CreateMissionLaunchRequest.MissionId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user