Skip to content

Commit

Permalink
test: check that correct events are emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Oct 18, 2023
1 parent f8ac5c5 commit e3ef348
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ describe('Cost Surface', () => {

// ASSERT
await fixtures.ThenCostSurfaceAPIEntityWasProperlySaved(costSurfaceName);
await fixtures.ThenCostSurfaceUploadEventsShouldReflectThatProjectCostSurfaceUploadWasSuccessful(costSurfaceName);
});

it(`should return error when the cost surface name is empty`, async () => {
Expand Down Expand Up @@ -211,6 +212,7 @@ describe('Cost Surface', () => {

// ASSERT
await fixtures.ThenCostSurfaceAPIEntityWasProperlySaved(costSurfaceName);
await fixtures.ThenCostSurfaceUploadEventsShouldReflectThatProjectCostSurfaceUploadWasSuccessful(costSurfaceName);
});

it(`should return error when the cost surface could not be found`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ import { EventBusTestUtils } from '../../utils/event-bus.test.utils';
import { CostSurfaceDeleted } from '@marxan-api/modules/cost-surface/events/cost-surface-deleted.event';
import { FakeQueue } from '../../utils/queues';
import { unusedResourcesCleanupQueueName } from '@marxan/unused-resources-cleanup';
<<<<<<< HEAD
import { scenarioCostSurfaceQueueName } from '@marxan/artifact-cache/cost-surface-queue-name';
import { ApiEventsService } from '@marxan-api/modules/api-events';
import { API_EVENT_KINDS } from '@marxan/api-events';
import { ScenarioRoles } from '@marxan-api/modules/access-control/scenarios-acl/dto/user-role-scenario.dto';
import { UsersScenariosApiEntity } from '@marxan-api/modules/access-control/scenarios-acl/entity/users-scenarios.api.entity';
import { ApiEvent } from '@marxan-api/modules/api-events/api-event.api.entity';
=======
import { ApiEvent } from '@marxan-api/modules/api-events/api-event.api.entity';
import { API_EVENT_KINDS } from '@marxan/api-events';
>>>>>>> 43b00b09c (test: check that correct events are emitted)

export const getProjectCostSurfaceFixtures = async () => {
const app = await bootstrapApplication(
Expand Down Expand Up @@ -87,9 +92,12 @@ export const getProjectCostSurfaceFixtures = async () => {
const usersProjectsApiRepo: Repository<UsersProjectsApiEntity> = app.get(
getRepositoryToken(UsersProjectsApiEntity),
);
<<<<<<< HEAD
const usersScenarioRolesRepo: Repository<UsersScenariosApiEntity> = app.get(
getRepositoryToken(UsersScenariosApiEntity),
);
=======
>>>>>>> 43b00b09c (test: check that correct events are emitted)
const apiEventsRepo: Repository<ApiEvent> = app.get(
getRepositoryToken(ApiEvent),
);
Expand Down Expand Up @@ -322,7 +330,21 @@ export const getProjectCostSurfaceFixtures = async () => {
}),
).rejects.toThrow(NotFoundException);
},

ThenCostSurfaceUploadEventsShouldReflectThatProjectCostSurfaceUploadWasSuccessful: async (name: string) => {
const savedCostSurface = await costSurfaceRepo.findOneOrFail({
where: { name },
});
const latestApiEventForProjectCostSurfaceUploadFinished = await apiEventsRepo.findOne({
where: { kind: API_EVENT_KINDS.project__costSurface_shapefile_submitted__v1alpha1, topic: savedCostSurface.projectId },
order: { timestamp: 'DESC' },
});
const latestApiEventForProjectCostSurfaceUploadSubmitted = await apiEventsRepo.findOne({
where: { kind: API_EVENT_KINDS.project__costSurface_shapefile_finished__v1alpha1, topic: savedCostSurface.projectId },
order: { timestamp: 'DESC' },
});
expect(latestApiEventForProjectCostSurfaceUploadSubmitted).toBeDefined();
expect(latestApiEventForProjectCostSurfaceUploadFinished).toBeDefined();
},
ThenResponseHasCostSurface: async (
response: request.Response,
costSurface: CostSurface,
Expand Down

0 comments on commit e3ef348

Please sign in to comment.