Skip to content

Commit

Permalink
SPSH-1286: Fixed code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
phaelcg committed Nov 29, 2024
1 parent 4f9ccae commit e89db13
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/modules/import/api/import.controller.integration-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Import API', () => {
await DatabaseTestModule.clearDatabase(orm);
});

describe('/POST import', () => {
describe('/POST upload', () => {
it('should return 201 OK with ImportUploadResponse', async () => {
const filePath: string = path.resolve('./', `test/imports/valid_test_import_SuS.csv`);

Expand Down Expand Up @@ -447,6 +447,53 @@ describe('Import API', () => {
invalidImportDataItems: [],
});
});

it('should return 404 if the logged-in admin has no username', async () => {
const filePath: string = path.resolve('./', `test/imports/valid_test_import_SuS.csv`);

const fileExists: boolean = fs.existsSync(filePath);
if (!fileExists) throw new Error('file does not exist');

const schule: OrganisationEntity = new OrganisationEntity();
schule.typ = OrganisationsTyp.SCHULE;
schule.name = 'Import Schule';
await em.persistAndFlush(schule);
await em.findOneOrFail(OrganisationEntity, { id: schule.id });

const klasse: OrganisationEntity = new OrganisationEntity();
klasse.typ = OrganisationsTyp.KLASSE;
klasse.name = '1a';
klasse.administriertVon = schule.id;
klasse.zugehoerigZu = schule.id;
await em.persistAndFlush(klasse);
await em.findOneOrFail(OrganisationEntity, { id: klasse.id });

const sus: Rolle<true> | DomainError = await rolleRepo.save(
DoFactory.createRolle(false, {
rollenart: RollenArt.LERN,
administeredBySchulstrukturknoten: schule.id,
merkmale: [],
}),
);
if (sus instanceof DomainError) throw sus;

personPermissionsMock.personFields.username = undefined;

const response: Response = await request(app.getHttpServer() as App)
.post('/import/upload')
.set('content-type', 'multipart/form-data')
.field('organisationId', schule.id)
.field('rolleId', sus.id)
.attach('file', filePath);

expect(response.status).toBe(404);
expect(response.body).toEqual({
code: 404,
subcode: '01',
titel: 'Angefragte Entität existiert nicht',
beschreibung: 'Die angeforderte Entität existiert nicht',
});
});
});

describe('/POST execute', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,17 @@ describe('ImportVorgangRepository', () => {
expect(result.length).toBe(1);
expect(total).toBe(1);
});

it('should return an empty array if no import transaction was found', async () => {
const permissions: DeepMocked<PersonPermissions> = createMock<PersonPermissions>();
permissions.hasSystemrechteAtRootOrganisation.mockResolvedValueOnce(true);

const [result, total]: [ImportVorgang<true>[], number] = await sut.findAuthorized(permissions, {
status: ImportStatus.FAILED,
});

expect(result.length).toBe(0);
expect(total).toBe(0);
});
});
});

0 comments on commit e89db13

Please sign in to comment.