Skip to content

Instantly share code, notes, and snippets.

@endurance
Created March 26, 2020 14:04
Show Gist options
  • Save endurance/d9036ec3dfe2070eaa9078099228d872 to your computer and use it in GitHub Desktop.
Save endurance/d9036ec3dfe2070eaa9078099228d872 to your computer and use it in GitHub Desktop.
import { setupTestDatabase, TestPackage } from '../../../../db/testing/setupTestDatabase';
import { JobService } from './job.service';
import { FixtureResolver } from '../../../../db/testing/fixture.loader';
import { SERVICE_DB } from '../../../../db/tokens';
import { CreateJobInput } from '../../../job-list-view/inputs/create-job.input';
import { v4 } from 'uuid';
import { UpdateJobInput } from '../../../job-list-view/inputs/update-job.input';
describe('Test Jobs', () => {
let pkg: TestPackage;
const fixture = new FixtureResolver([SERVICE_DB]);
beforeAll(async () => {
pkg = await setupTestDatabase({
providers: [JobService],
});
await fixture.load('./');
});
it('should find by id', async () => {
const service = await pkg.module.get(JobService);
const id = '31627553-a0af-4d82-953f-d0bb69d2ab20';
const job = await service.findById(id);
expect(job.id).toBe(id);
});
const createJob = async (proliantId: string) => {
const service = await pkg.module.get<JobService>(JobService);
const input = new CreateJobInput();
input.employment_type = '1099';
input.jobsheetTemplateTypeName = 'Master Template 24 Hour';
input.company_name = 'Test Name';
input.consultant_provider = 'RUSCO';
input.legal_first_name = 'Endurance';
input.legal_middle_name = '';
input.legal_last_name = 'Idehen';
input.msa_provider = 'RUDTUK';
input.proliant_id = proliantId;
input.service_name = 'Admin';
const job = await service.createNewJob(input);
expect(job).toBeDefined();
return job;
};
it('should create job', async () => {
const job = await createJob(v4());
});
it('should update job', async () => {
const proliantId = v4();
const job = await createJob(proliantId);
const service = await pkg.module.get<JobService>(JobService);
const input = new UpdateJobInput();
input.id = job.id;
input.employment_type = '1099';
input.jobsheetTemplateTypeName = 'Master Template 24 Hour';
input.company_name = 'Test Name';
input.consultant_provider = 'RUSCO';
input.legal_first_name = 'A different name';
input.legal_last_name = 'Again';
input.msa_provider = 'RUDTUK';
input.proliant_id = proliantId;
input.service_name = 'Admin';
await service.updateJob(input);
const jobEntity = await service.findById(input.id, { relations: ['Person'] });
expect(jobEntity.Person.legal_first_name).toBe(input.legal_first_name);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment