Skip to content

Commit

Permalink
basic first initial test for maps
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Oct 25, 2024
1 parent 2bbe322 commit 501acff
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
30 changes: 30 additions & 0 deletions api/test/integration/map/map.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { TestManager } from '../../utils/test-manager';
import { HttpStatus } from '@nestjs/common';

describe('Map', () => {
let testManager: TestManager;

beforeAll(async () => {
testManager = await TestManager.createTestManager();
});

afterEach(async () => {
await testManager.clearDatabase();
});

afterAll(async () => {
await testManager.close();
});

test('should return a geojson given a countryCode', async () => {
await testManager.ingestCountries();
await testManager.mocks().createBaseData({ countryCode: 'AND' });
const response = await testManager
.request()
.get('/map/geo-features')
.query({ countryCode: 'AND' });

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.features.length).toBe(1);
});
});
5 changes: 4 additions & 1 deletion api/test/utils/test-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { User } from '@shared/entities/users/user.entity';
import { IEmailServiceToken } from '@api/modules/notifications/email/email-service.interface';
import { MockEmailService } from './mocks/mock-email.service';
import { ROLES } from '@shared/entities/users/roles.enum';
import { createUser } from '@shared/lib/entity-mocks';
import { createBaseData, createUser } from '@shared/lib/entity-mocks';
import { clearTestDataFromDatabase } from '@shared/lib/db-helpers';
import * as path from 'path';
import * as fs from 'fs';
import { BaseData } from '@shared/entities/base-data.entity';
/**
* @description: Abstraction for NestJS testing workflow. For now its a basic implementation to create a test app, but can be extended to encapsulate
* common testing utilities
Expand Down Expand Up @@ -102,6 +103,8 @@ export class TestManager {
return {
createUser: (additionalData?: Partial<User>) =>
createUser(this.getDataSource(), additionalData),
createBaseData: async (additionalData?: Partial<BaseData>) =>
createBaseData(this.getDataSource(), additionalData),
};
}
}
17 changes: 17 additions & 0 deletions shared/lib/entity-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { genSalt, hash } from "bcrypt";
import { DataSource, DeepPartial } from "typeorm";
import { User } from "@shared/entities/users/user.entity";
import {
ACTIVITY,
BaseData,
ECOSYSTEM,
} from "@shared/entities/base-data.entity";

export const createUser = async (
dataSource: DataSource,
Expand All @@ -18,3 +23,15 @@ export const createUser = async (
await dataSource.getRepository(User).save(user);
return { ...user, password: usedPassword } as User;
};

export const createBaseData = async (
dataSource: DataSource,
additionalData?: Partial<BaseData>,
): Promise<BaseData> => {
const baseData = new BaseData();
baseData.ecosystem = ECOSYSTEM.MANGROVE;
baseData.countryCode = "AND";
baseData.activity = ACTIVITY.CONSERVATION;

return dataSource.getRepository(BaseData).save(baseData);
};

0 comments on commit 501acff

Please sign in to comment.