Skip to content

Commit 4a90c10

Browse files
committed
fix: add more tests
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent f03d9b8 commit 4a90c10

File tree

3 files changed

+179
-3
lines changed

3 files changed

+179
-3
lines changed

packages/cli/lib/base-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ module.exports = class BaseGenerator extends Generator {
461461
);
462462
}
463463
}
464-
// process.exit(0);
464+
process.exit(0);
465465
}
466466

467467
/**

packages/cli/snapshots/integration/generators/discover.integration.snapshots.js

Lines changed: 174 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,92 @@ import {
6666
get,
6767
getModelSchemaRef,
6868
} from '@loopback/rest';
69+
import {
70+
Appointment,
71+
Doctor,
72+
} from '../models';
73+
import {AppointmentRepository} from '../repositories';
74+
75+
export class AppointmentDoctorController {
76+
constructor(
77+
@repository(AppointmentRepository)
78+
public appointmentRepository: AppointmentRepository,
79+
) { }
80+
81+
@get('/appointments/{id}/doctor', {
82+
responses: {
83+
'200': {
84+
description: 'Doctor belonging to Appointment',
85+
content: {
86+
'application/json': {
87+
schema: getModelSchemaRef(Doctor),
88+
},
89+
},
90+
},
91+
},
92+
})
93+
async getDoctor(
94+
@param.path.number('id') id: typeof Appointment.prototype.id,
95+
): Promise<Doctor> {
96+
return this.appointmentRepository.doctor(id);
97+
}
98+
}
99+
100+
`;
101+
102+
103+
exports[`lb4 discover integration model discovery discovers models with --relations 2`] = `
104+
import {
105+
repository,
106+
} from '@loopback/repository';
107+
import {
108+
param,
109+
get,
110+
getModelSchemaRef,
111+
} from '@loopback/rest';
112+
import {
113+
Appointment,
114+
Patient,
115+
} from '../models';
116+
import {AppointmentRepository} from '../repositories';
117+
118+
export class AppointmentPatientController {
119+
constructor(
120+
@repository(AppointmentRepository)
121+
public appointmentRepository: AppointmentRepository,
122+
) { }
123+
124+
@get('/appointments/{id}/patient', {
125+
responses: {
126+
'200': {
127+
description: 'Patient belonging to Appointment',
128+
content: {
129+
'application/json': {
130+
schema: getModelSchemaRef(Patient),
131+
},
132+
},
133+
},
134+
},
135+
})
136+
async getPatient(
137+
@param.path.number('id') id: typeof Appointment.prototype.id,
138+
): Promise<Patient> {
139+
return this.appointmentRepository.patient(id);
140+
}
141+
}
142+
143+
`;
144+
145+
146+
exports[`lb4 discover integration model discovery discovers models with --relations 3`] = `
147+
import {
148+
repository,
149+
} from '@loopback/repository';
150+
import {
151+
param,
152+
get,
153+
getModelSchemaRef,
154+
} from '@loopback/rest';
69155
import {
70156
Doctor,
71157
} from '../models';
@@ -99,7 +185,7 @@ export class DoctorDoctorController {
99185
`;
100186

101187

102-
exports[`lb4 discover integration model discovery discovers models with --relations 2`] = `
188+
exports[`lb4 discover integration model discovery discovers models with --relations 4`] = `
103189
import {Entity, model, property, belongsTo} from '@loopback/repository';
104190
105191
@model()
@@ -205,6 +291,92 @@ import {
205291
get,
206292
getModelSchemaRef,
207293
} from '@loopback/rest';
294+
import {
295+
Appointment,
296+
Doctor,
297+
} from '../models';
298+
import {AppointmentRepository} from '../repositories';
299+
300+
export class AppointmentDoctorController {
301+
constructor(
302+
@repository(AppointmentRepository)
303+
public appointmentRepository: AppointmentRepository,
304+
) { }
305+
306+
@get('/appointments/{id}/doctor', {
307+
responses: {
308+
'200': {
309+
description: 'Doctor belonging to Appointment',
310+
content: {
311+
'application/json': {
312+
schema: getModelSchemaRef(Doctor),
313+
},
314+
},
315+
},
316+
},
317+
})
318+
async getDoctor(
319+
@param.path.number('id') id: typeof Appointment.prototype.id,
320+
): Promise<Doctor> {
321+
return this.appointmentRepository.doctor(id);
322+
}
323+
}
324+
325+
`;
326+
327+
328+
exports[`lb4 discover integration model discovery generate relations with --relations 2`] = `
329+
import {
330+
repository,
331+
} from '@loopback/repository';
332+
import {
333+
param,
334+
get,
335+
getModelSchemaRef,
336+
} from '@loopback/rest';
337+
import {
338+
Appointment,
339+
Patient,
340+
} from '../models';
341+
import {AppointmentRepository} from '../repositories';
342+
343+
export class AppointmentPatientController {
344+
constructor(
345+
@repository(AppointmentRepository)
346+
public appointmentRepository: AppointmentRepository,
347+
) { }
348+
349+
@get('/appointments/{id}/patient', {
350+
responses: {
351+
'200': {
352+
description: 'Patient belonging to Appointment',
353+
content: {
354+
'application/json': {
355+
schema: getModelSchemaRef(Patient),
356+
},
357+
},
358+
},
359+
},
360+
})
361+
async getPatient(
362+
@param.path.number('id') id: typeof Appointment.prototype.id,
363+
): Promise<Patient> {
364+
return this.appointmentRepository.patient(id);
365+
}
366+
}
367+
368+
`;
369+
370+
371+
exports[`lb4 discover integration model discovery generate relations with --relations 3`] = `
372+
import {
373+
repository,
374+
} from '@loopback/repository';
375+
import {
376+
param,
377+
get,
378+
getModelSchemaRef,
379+
} from '@loopback/rest';
208380
import {
209381
Doctor,
210382
} from '../models';
@@ -238,7 +410,7 @@ export class DoctorDoctorController {
238410
`;
239411

240412

241-
exports[`lb4 discover integration model discovery generate relations with --relations 2`] = `
413+
exports[`lb4 discover integration model discovery generate relations with --relations 4`] = `
242414
import {Entity, model, property, belongsTo} from '@loopback/repository';
243415
import {Doctor} from './doctor.model';
244416
import {Patient} from './patient.model';

packages/cli/test/integration/generators/discover.integration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ describe('lb4 discover integration', () => {
254254
assert.file(appointmentDoctorController);
255255
assert.file(appointmentPatientController);
256256
assert.file(doctorDoctorController);
257+
expectFileToMatchSnapshot(appointmentDoctorController);
258+
expectFileToMatchSnapshot(appointmentPatientController);
257259
expectFileToMatchSnapshot(doctorDoctorController);
258260
assert.file(appointmentModel);
259261
expectFileToMatchSnapshot(appointmentModel);
@@ -274,6 +276,8 @@ describe('lb4 discover integration', () => {
274276
assert.file(appointmentDoctorController);
275277
assert.file(appointmentPatientController);
276278
assert.file(doctorDoctorController);
279+
expectFileToMatchSnapshot(appointmentDoctorController);
280+
expectFileToMatchSnapshot(appointmentPatientController);
277281
expectFileToMatchSnapshot(doctorDoctorController);
278282
assert.file(doctorModel);
279283
expectFileToMatchSnapshot(doctorModel);

0 commit comments

Comments
 (0)