Skip to content

Commit

Permalink
Fixes unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
digimezzo committed Dec 9, 2024
1 parent da6f8f2 commit 4b0b2d9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 137 deletions.
6 changes: 3 additions & 3 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EventListenerServiceBase } from './services/event-listener/event-listen
import { MediaSessionService } from './services/media-session/media-session.service';
import { TrayServiceBase } from './services/tray/tray.service.base';
import { ScrobblingServiceBase } from './services/scrobbling/scrobbling.service.base';
import { DiscordServiceBase } from './services/discord/discord.service.base';
import { DiscordService } from './services/discord/discord.service';
import { TranslatorServiceBase } from './services/translator/translator.service.base';
import { AppearanceServiceBase } from './services/appearance/appearance.service.base';
import { NavigationServiceBase } from './services/navigation/navigation.service.base';
Expand All @@ -27,7 +27,7 @@ describe('AppComponent', () => {
let navigationServiceMock: IMock<NavigationServiceBase>;
let appearanceServiceMock: IMock<AppearanceServiceBase>;
let translatorServiceMock: IMock<TranslatorServiceBase>;
let discordServiceMock: IMock<DiscordServiceBase>;
let discordServiceMock: IMock<DiscordService>;
let scrobblingServiceMock: IMock<ScrobblingServiceBase>;
let trayServiceMock: IMock<TrayServiceBase>;
let mediaSessionServiceMock: IMock<MediaSessionService>;
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('AppComponent', () => {
navigationServiceMock = Mock.ofType<NavigationServiceBase>();
appearanceServiceMock = Mock.ofType<AppearanceServiceBase>();
translatorServiceMock = Mock.ofType<TranslatorServiceBase>();
discordServiceMock = Mock.ofType<DiscordServiceBase>();
discordServiceMock = Mock.ofType<DiscordService>();
scrobblingServiceMock = Mock.ofType<ScrobblingServiceBase>();
trayServiceMock = Mock.ofType<TrayServiceBase>();
mediaSessionServiceMock = Mock.ofType<MediaSessionService>();
Expand Down
158 changes: 24 additions & 134 deletions src/app/services/discord/discord.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('DiscordService', () => {
trackModel = new TrackModel(track, dateTimeMock.object, translatorServiceMock.object, '');
track.duration = 200000;

dateProxyMock.setup((x) => x.now()).returns(() => 10);
dateProxyMock.setup((x) => x.now()).returns(() => 5000);
});

function setUpPlaybackServiceMock(isPlaying: boolean, canPause: boolean): void {
Expand All @@ -77,7 +77,7 @@ describe('DiscordService', () => {

playbackServiceMock.setup((x) => x.currentTrack).returns(() => trackModel);

const progress: PlaybackProgress = new PlaybackProgress(20, 120);
const progress: PlaybackProgress = new PlaybackProgress(2, 120);
playbackServiceMock.setup((x) => x.progress).returns(() => progress);

playbackServiceMock.setup((x) => x.isPlaying).returns(() => isPlaying);
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -153,7 +153,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -174,7 +174,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0, 0),
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0),
Times.once(),
);
});
Expand All @@ -195,7 +195,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -216,7 +216,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -237,7 +237,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0, 0),
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0),
Times.once(),
);
});
Expand Down Expand Up @@ -278,18 +278,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -310,18 +299,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -342,18 +320,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -374,18 +341,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -406,18 +362,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand Down Expand Up @@ -463,7 +408,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -481,7 +426,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -499,7 +444,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0, 0),
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0),
Times.once(),
);
});
Expand All @@ -517,7 +462,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -535,7 +480,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 10, 100010),
(x) => x.updatePresence('title', 'artist1, artist2', 'play', 'Playing', 'icon', 'Playing with Dopamine', true, 3000),
Times.once(),
);
});
Expand All @@ -553,7 +498,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0, 0),
(x) => x.updatePresence('title', 'artist1, artist2', 'pause', 'Paused', 'icon', 'Playing with Dopamine', false, 0),
Times.once(),
);
});
Expand Down Expand Up @@ -588,18 +533,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -617,18 +551,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -646,18 +569,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -675,18 +587,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand All @@ -704,18 +605,7 @@ describe('DiscordService', () => {

// Assert
presenceUpdaterMock.verify(
(x) =>
x.updatePresence(
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
It.isAny(),
),
(x) => x.updatePresence(It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny(), It.isAny()),
Times.never(),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SignInState } from '../../../../services/scrobbling/sign-in-state';
import { NotificationServiceBase } from '../../../../services/notification/notification.service.base';
import { DiscordService } from '../../../../services/discord/discord.service';

jest.mock('jimp', () => ({ exec: jest.fn() }));

describe('OnlineSettingsComponent', () => {
let discordServiceMock: IMock<DiscordService>;
let scrobblingServiceMock: IMock<ScrobblingServiceBase>;
Expand Down

0 comments on commit 4b0b2d9

Please sign in to comment.