Skip to content

Commit

Permalink
BC-5639 - fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Nov 16, 2023
1 parent 7a9c7db commit 9d92307
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 41 deletions.
5 changes: 3 additions & 2 deletions src/services/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = function setup() {
function redirectToTarget(req, res, next) {
if (req.method === 'GET' && !req.query.target) {
// capture these requests and issue a redirect
const linkId = req.params.__feathersId;
// const linkId = req.params.__feathersId;
const linkId = req.lookup.params.__id;
linkService
.get(linkId)
.then((data) => {
Expand Down Expand Up @@ -137,7 +138,7 @@ module.exports = function setup() {
const { teamId } = data;

if (email) {
const { data: userData } = await app.service('users').find({ query: { email: email } });
const { data: userData } = await app.service('users').find({ query: { email } });
if (userData && userData[0] && userData[0].importHash) {
linkInfo.hash = userData[0].importHash;
} else {
Expand Down
26 changes: 13 additions & 13 deletions src/services/school/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ module.exports = function schoolServices() {
const app = this;

app.use('/schools/api', staticContent(path.join(__dirname, '/docs/openapi.yaml')));

const options = {
Model: schoolModels.schoolModel,
paginate: {
default: 5,
max: 100, // this is the max currently used in the SHD
},
lean: {
virtuals: true,
},
};

app.use('/schools', service(options));
app.use(
'/schools',
service({
Model: schoolModels.schoolModel,
paginate: {
default: 5,
max: 100, // this is the max currently used in the SHD
},
lean: {
virtuals: true,
},
})
);
const schoolService = app.service('/schools');
schoolService.hooks(hooks);

Expand Down
2 changes: 2 additions & 0 deletions test/services/account/services/jwtTimerService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('jwtTimer service', () => {
/* eslint-disable global-require */
redisHelper = require('../../../../src/utils/redis');
const { jwtTimerServiceSetup } = require('../../../../src/services/account/services/jwtTimerService');
app.unuse('/accounts/jwtTimer');
app.configure(jwtTimerServiceSetup);
/* eslint-enable global-require */

Expand Down Expand Up @@ -105,6 +106,7 @@ describe('jwtTimer service', () => {
/* eslint-disable global-require */
redisHelper = require('../../../../src/utils/redis');
const { jwtTimerServiceSetup } = require('../../../../src/services/account/services/jwtTimerService');
app.unuse('/accounts/jwtTimer');
app.configure(jwtTimerServiceSetup);
/* eslint-enable global-require */

Expand Down
6 changes: 1 addition & 5 deletions test/services/content/material.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ describe('material service', () => {

before(async () => {
app = await appPromise();
server = await app.listen(0);
nestServices = await setupNestServices(app);
server = await app.listen(0);
});

after(async () => {
Expand All @@ -41,10 +41,6 @@ describe('material service', () => {
let materialA;
let materialB;

before((done) => {
server = app.listen(0, done);
});

before(async () => {
[materialA, materialB] = await Promise.all([
Material.create({
Expand Down
3 changes: 3 additions & 0 deletions test/services/datasources/datasourceRuns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ describe('datasourceRuns service', () => {
});
mockery.registerMock('./strategies', [MockSyncer, MockSyncerWithData]);
datasourceRunsService = app.service('datasourceRuns');

app.unuse('/sync/userAccount');
app.unuse('/sync');
// eslint-disable-next-line global-require
const sync = require('../../../src/services/sync');
app.configure(sync);
Expand Down
7 changes: 6 additions & 1 deletion test/services/helpdesk/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
const assert = require('assert');
const { expect } = require('chai');
const sinon = require('sinon');
const appPromise = require('../../../src/app');
const { Configuration } = require('@hpi-schul-cloud/commons');
const appPromise = require('../../../src/app');

describe('helpdesk service', function test() {
this.timeout(10000);
Expand Down Expand Up @@ -36,6 +36,7 @@ describe('helpdesk service', function test() {
});

after((done) => {
app.unuse('/mails');
app.use('/mails', originalMailService);
helpdeskService
.remove(testProblem)
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('helpdesk service', function test() {
problemDescription: 'Dies ist die Problembeschreibung 1',
replyEmail: '[email protected]',
};
app.unuse('/mails');
const mailService = new MockMailService();
app.use('/mails', mailService);
await helpdeskService.create(postBody, { account: { userId: '0000d213816abba584714c0a' } });
Expand All @@ -129,6 +131,7 @@ describe('helpdesk service', function test() {
problemDescription: 'Dies ist die Problembeschreibung 1',
replyEmail: '[email protected]',
};
app.unuse('/mails');
const mailService = new MockMailService();
app.use('/mails', mailService);
const tempScTheme = Configuration.get('SUPPORT_PROBLEM_EMAIL_ADDRESS');
Expand All @@ -146,6 +149,7 @@ describe('helpdesk service', function test() {
problemDescription: 'Dies ist die Problembeschreibung 1',
replyEmail: '[email protected]',
};
app.unuse('/mails');
const mailService = new MockMailService();
app.use('/mails', mailService);
await helpdeskService.create(postBody, { account: { userId: '0000d213816abba584714c0a' } });
Expand All @@ -161,6 +165,7 @@ describe('helpdesk service', function test() {
problemDescription: 'Dies ist die Problembeschreibung 2',
replyEmail: '[email protected]',
};
app.unuse('/mails');
const mailService = new MockMailService();
app.use('/mails', mailService);
const tempScTheme = Configuration.get('SUPPORT_WISH_EMAIL_ADDRESS');
Expand Down
27 changes: 17 additions & 10 deletions test/services/ldap-config/service.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,28 @@ describe('LdapConfigService', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
getUsers: sinon.fake.resolves(fakeUsers),
getClasses: sinon.fake.resolves(fakeClasses),
disconnect: sinon.fake.resolves(),
};
}

beforeEach(() => {
ldapServiceMock = new MockLdapService();
app.use('ldap', ldapServiceMock);
});

before(() => {
originalLdapService = app.service('ldap');
});

after(() => {
app.unuse('ldap');
app.use('ldap', originalLdapService);
});

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('ldap', ldapServiceMock);
});

beforeEach(async () => {
school = await testObjects.createTestSchool({
systems: [],
Expand Down Expand Up @@ -223,6 +226,7 @@ describe('LdapConfigService', () => {
});

it('should catch common errors', async () => {
app.unuse('ldap');
ldapServiceMock.getUsers = sinon.fake.rejects(new LDAPConnectionError());
app.use('ldap', ldapServiceMock);

Expand Down Expand Up @@ -287,25 +291,28 @@ describe('LdapConfigService', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
getUsers: sinon.fake.resolves(fakeUsers),
getClasses: sinon.fake.resolves(fakeClasses),
disconnect: sinon.fake.resolves(),
};
}

beforeEach(() => {
ldapServiceMock = new MockLdapService();
app.use('ldap', ldapServiceMock);
});

before(() => {
originalLdapService = app.service('ldap');
});

after(() => {
app.unuse('ldap');
app.use('ldap', originalLdapService);
});

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('/ldap', ldapServiceMock);
});

beforeEach(async () => {
system = await testObjects.createTestSystem({
type: 'ldap',
Expand Down
1 change: 1 addition & 0 deletions test/services/ldap/strategies/general.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('GeneralLDAPStrategy', () => {
});

after(() => {
app.unuse('/ldap');
app.use('/ldap', originalLdapService);
});

Expand Down
7 changes: 7 additions & 0 deletions test/services/ldap/strategies/iserv-idm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ describe('IservIdmLDAPStrategy', () => {
});

after(() => {
app.unuse('/ldap');
app.use('/ldap', originalLdapService);
});

describe('#getSchools', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
searchCollection: sinon.fake.returns([
{ dn: 'o=Testschule,dc=de', o: 'Testschule' },
{ dn: 'o=hvk,dc=schule', description: 'Heinrich-von-Kleist-Schule', o: 'hvk' },
Expand All @@ -37,6 +39,7 @@ describe('IservIdmLDAPStrategy', () => {
}

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('/ldap', ldapServiceMock);
});
Expand Down Expand Up @@ -86,6 +89,7 @@ describe('IservIdmLDAPStrategy', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
searchCollection: sinon.fake.returns([
{
dn: 'cn=student1,ou=users,o=Testschule,dc=de',
Expand Down Expand Up @@ -153,6 +157,7 @@ describe('IservIdmLDAPStrategy', () => {
}

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('/ldap', ldapServiceMock);
});
Expand Down Expand Up @@ -206,6 +211,7 @@ describe('IservIdmLDAPStrategy', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
searchCollection: sinon.fake.returns([
{
dn: 'cn=klasse9a,ou=groups,o=Testschule,dc=de',
Expand All @@ -228,6 +234,7 @@ describe('IservIdmLDAPStrategy', () => {
}

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('/ldap', ldapServiceMock);
});
Expand Down
7 changes: 7 additions & 0 deletions test/services/ldap/strategies/univention.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('UniventionLDAPStrategy', () => {
});

after(() => {
app.unuse('/ldap');
app.use('/ldap', originalLdapService);
});

Expand All @@ -39,11 +40,13 @@ describe('UniventionLDAPStrategy', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
searchCollection: sinon.fake.resolves(ldapFakeSchoolSearchResult),
};
}

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('/ldap', ldapServiceMock);
});
Expand Down Expand Up @@ -122,6 +125,7 @@ describe('UniventionLDAPStrategy', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
searchCollection: sinon.fake.resolves([
{
dn: 'uid=max1,cn=schueler,cn=users,ou=1,dc=training,dc=ucs',
Expand Down Expand Up @@ -165,6 +169,7 @@ describe('UniventionLDAPStrategy', () => {
}

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('/ldap', ldapServiceMock);
});
Expand Down Expand Up @@ -241,11 +246,13 @@ describe('UniventionLDAPStrategy', () => {
function MockLdapService() {
return {
setup: () => {},
get: () => {},
searchCollection: sinon.fake.resolves(ldapFakeClassSearchResult),
};
}

beforeEach(() => {
app.unuse('/ldap');
ldapServiceMock = new MockLdapService();
app.use('/ldap', ldapServiceMock);
});
Expand Down
12 changes: 8 additions & 4 deletions test/services/news/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ const sleep = require('util').promisify(setTimeout);

const appPromise = require('../../../src/app');
const { newsModel: News } = require('../../../src/services/news/model');
const { setupNestServices, closeNestServices } = require('../../utils/setup.nest.services');

describe('news service', () => {
let app;
let newsService;
let server;
let nestServices;

before(async () => {
app = await appPromise();
newsService = app.service('news');
nestServices = await setupNestServices(app);
server = await app.listen(0);
});

it('public service has been disabled', () => {
expect(newsService, 'use v3 instead').to.equal(undefined);
after(async () => {
await server.close();
await closeNestServices(nestServices);
});

describe('event handlers', () => {
Expand Down
Loading

0 comments on commit 9d92307

Please sign in to comment.