123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import { faker } from "@faker-js/faker";
- import {
- JobStatistic,
- JobStatistics,
- JobStatisticsType
- } from "./JobStatistics";
- describe("JobStatistics", function () {
- describe("getStats", function () {
- it("should include jobs statistics", function () {
- const statistics = new JobStatistics();
- const jobName = faker.lorem.text();
- statistics.updateStats(jobName, JobStatisticsType.TOTAL);
- statistics.getStats()[jobName].total.should.be.equal(1);
- });
- [
- JobStatisticsType.CONSTRUCTED,
- JobStatisticsType.FAILED,
- JobStatisticsType.QUEUED,
- JobStatisticsType.SUCCESSFUL,
- JobStatisticsType.TOTAL
- ].forEach(function (type) {
- it(`should sum ${type} count for total`, function () {
- const statistics = new JobStatistics();
- statistics.updateStats(faker.lorem.text(), type);
- statistics.updateStats(faker.lorem.text(), type);
- statistics
- .getStats()
- .total[type as keyof JobStatistic].should.be.equal(2);
- });
- });
- it(`should sum total duration for total`, function () {
- const statistics = new JobStatistics();
- const firstDuration = faker.number.int();
- const secondDuration = faker.number.int();
- const totalDuration = firstDuration + secondDuration;
- statistics.updateStats(
- faker.lorem.text(),
- JobStatisticsType.DURATION,
- firstDuration
- );
- statistics.updateStats(
- faker.lorem.text(),
- JobStatisticsType.DURATION,
- secondDuration
- );
- statistics
- .getStats()
- .total.totalTime.should.be.equal(totalDuration);
- });
- it("should calculate average time for total", function () {
- const statistics = new JobStatistics();
- const firstJobName = faker.lorem.text();
- const secondJobName = faker.lorem.text();
- const firstDuration = faker.number.int();
- const secondDuration = faker.number.int();
- const averageDuration = (firstDuration + secondDuration) / 2;
- statistics.updateStats(firstJobName, JobStatisticsType.TOTAL);
- statistics.updateStats(
- firstJobName,
- JobStatisticsType.DURATION,
- firstDuration
- );
- statistics.updateStats(secondJobName, JobStatisticsType.TOTAL);
- statistics.updateStats(
- secondJobName,
- JobStatisticsType.DURATION,
- secondDuration
- );
- statistics
- .getStats()
- .total.averageTime.should.be.equal(averageDuration);
- });
- });
- describe("updateStats", function () {
- const jobName = faker.lorem.text();
- [
- JobStatisticsType.CONSTRUCTED,
- JobStatisticsType.FAILED,
- JobStatisticsType.QUEUED,
- JobStatisticsType.SUCCESSFUL,
- JobStatisticsType.TOTAL
- ].forEach(function (type) {
- it(`should increment ${type} count`, function () {
- const statistics = new JobStatistics();
- statistics.updateStats(jobName, type);
- statistics.updateStats(jobName, type);
- statistics
- .getStats()
- [jobName][type as keyof JobStatistic].should.be.equal(2);
- });
- });
- it(`should add to total duration`, function () {
- const statistics = new JobStatistics();
- const firstDuration = faker.number.int();
- const secondDuration = faker.number.int();
- const totalDuration = firstDuration + secondDuration;
- statistics.updateStats(
- jobName,
- JobStatisticsType.DURATION,
- firstDuration
- );
- statistics.updateStats(
- jobName,
- JobStatisticsType.DURATION,
- secondDuration
- );
- statistics
- .getStats()
- [jobName].totalTime.should.be.equal(totalDuration);
- });
- it("should calculate average time", function () {
- const statistics = new JobStatistics();
- const firstDuration = faker.number.int();
- const secondDuration = faker.number.int();
- const averageDuration = (firstDuration + secondDuration) / 2;
- statistics.updateStats(jobName, JobStatisticsType.TOTAL);
- statistics.updateStats(
- jobName,
- JobStatisticsType.DURATION,
- firstDuration
- );
- statistics.updateStats(jobName, JobStatisticsType.TOTAL);
- statistics.updateStats(
- jobName,
- JobStatisticsType.DURATION,
- secondDuration
- );
- statistics
- .getStats()
- [jobName].averageTime.should.be.equal(averageDuration);
- });
- });
- });
|