I am relatively new to writing test cases. I have a service in typescript for which I am planning to write test file. It contains nested methods. They do not contain return statements. Should I write test cases just for main method. As it does not contain no return statement how could I test my file? If someone could help me with testing of this file it would be much appreciated.
@Injectable()
export class MessageService {
constructor(
private readonly httpService: HttpService,
private readonly messagePublishService: MessagePublishService,
private readonly configService: ConfigService,
) {}
message = new ProductMessage();
publishMessages(productEvent: ProductEvent): Observable<any> {
let json = '';
const url = this.configService.get('SITEMAP_ENDPOINT');
const urls = [url + '/sitemap/retrieve/ide', url + '/sitemap/retrieve/tpd'];
try {
for (let i = 0; i < urls.length; i++) {
return https.get(urls[i], res => {
res.on('data', chunk => {
json += chunk;
});
res.on('end', () => {
const result = JSON.parse(json);
getProductCodes(productEvent, result, this.messagePublishService);
});
});
}
} catch (err) {
console.error(err);
}
}
}
function getProductCodes(
productEvent,
result,
messagePublishService: MessagePublishService,
) {
const splitCodes = productEvent.productCodes.split(',');
const splitvehicleType = productEvent.vehicleType.split(',');
const source: string = 'PCS_DATACACHE_TOPIC_ARN';
for (let i = 0; i < result.length; i++) {
for (let j = 0; j < result[i].products.length; j++) {
if (
productEvent.productCodes.length !== 0 &&
productEvent.productCodes !== undefined
) {
searchProductCode(
messagePublishService,
splitCodes,
result,
i,
j,
source,
);
} else {
console.log('No data found');
return;
}
}
}
}
function searchProductCode(
messagePublishService,
splitCodes,
result,
i,
j,
source,
) {
for (let k = 0; k < splitCodes.length; k++) {
if (result[i].products[j].productCode === splitCodes[k]) {
console.log(
'Product Codes: ' +
result[i].products[j].productCode +
' Country : ' +
result[i].country +
' Language : ' +
result[i].language,
);
const message: string =
'Product Codes: ' +
result[i].products[j].productCode +
' Country : ' +
result[i].country +
' Language : ' +
result[i].language;
messagePublishService.publish(source, message);
}
}
}
Aucun commentaire:
Enregistrer un commentaire