forked from patryk-zielinski93/sdj-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add abstraction to handle mocking in tests.
- Loading branch information
1 parent
ed0f8ba
commit 5244ed4
Showing
135 changed files
with
1,830 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
INSERT INTO sdj_test.channel (defaultStreamUrl, id, isRunning, name, usersOnline) VALUES (null, '12345', 0, null, 1); | ||
INSERT INTO sdj_test.user (displayName, id, name, realName) VALUES ('Maciek', 'U9SNE3S31', 'mikon0096', 'Maciej Sikorski'); | ||
INSERT INTO sdj_test.track (createdAt, duration, id, skips, title, addedById) VALUES ('2019-05-21 08:58:28', 210, '_4VCpTZye10', 0, 'Three Days Grace - Break (Official Music Video)', 'U9SNE3S31'); | ||
INSERT INTO sdj_test.track (createdAt, duration, id, skips, title, addedById) VALUES ('2019-10-01 20:46:16', 175, '_D1rrdFcj1U', 0, 'Matoma & Enrique Iglesias – I Don''t Dance (Without You) [feat. Konshens] [Official Lyric Video]', 'U9SNE3S31'); | ||
INSERT INTO sdj_test.queued_track (createdAt, id, `order`, playedAt, randomized, addedById, trackId, playedInId) VALUES ('2019-05-19 20:56:59', 2, 0, null, 0, 'U9SNE3S31', '_4VCpTZye10', '12345'); | ||
INSERT INTO sdj_test.queued_track (createdAt, id, `order`, playedAt, randomized, addedById, trackId, playedInId) VALUES ('2019-05-19 21:02:36', 4, 0, null, 0, 'U9SNE3S31', '_D1rrdFcj1U', '12345'); | ||
INSERT INTO channel (defaultStreamUrl, id, isRunning, name, usersOnline) VALUES (null, '12345', 0, null, 1); | ||
INSERT INTO user (displayName, id, name, realName) VALUES ('Maciek', 'U9SNE3S31', 'mikon0096', 'Maciej Sikorski'); | ||
INSERT INTO track (createdAt, duration, id, skips, title, addedById) VALUES ('2019-05-21 08:58:28', 210, '_4VCpTZye10', 0, 'Three Days Grace - Break (Official Music Video)', 'U9SNE3S31'); | ||
INSERT INTO track (createdAt, duration, id, skips, title, addedById) VALUES ('2019-10-01 20:46:16', 175, '_D1rrdFcj1U', 0, 'Matoma & Enrique Iglesias – I Don''t Dance (Without You) [feat. Konshens] [Official Lyric Video]', 'U9SNE3S31'); | ||
INSERT INTO queued_track (createdAt, id, `order`, playedAt, randomized, addedById, trackId, playedInId) VALUES ('2019-05-19 20:56:59', 2, 0, null, 0, 'U9SNE3S31', '_4VCpTZye10', '12345'); | ||
INSERT INTO queued_track (createdAt, id, `order`, playedAt, randomized, addedById, trackId, playedInId) VALUES ('2019-05-19 21:02:36', 4, 0, null, 0, 'U9SNE3S31', '_D1rrdFcj1U', '12345'); |
84 changes: 84 additions & 0 deletions
84
apps/backend-e2e/src/integration/add-track-to-queue.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { | ||
TrackDataService, | ||
TrackService, | ||
} from '@sdj/backend/radio/core/application-services'; | ||
import { | ||
Channel, | ||
QueuedTrack, | ||
Track, | ||
User, | ||
} from '@sdj/backend/radio/core/domain'; | ||
import { SlackModule } from '@sdj/backend/radio/ui-slack'; | ||
import { WebSocketModule } from '@sdj/backend/radio/ui-web-socket'; | ||
import { BackendSharedTestingKernelModule } from '@sdj/backend/shared/kernel'; | ||
import { SlackService, SlackTestingService } from '@sikora00/nestjs-slack-bot'; | ||
import 'jest-marbles'; | ||
import { getRepository } from 'typeorm'; | ||
import { UserDataService } from '../../../../libs/backend/radio/ui-slack/src/lib/bot/lib/interceptors/user-data.service'; | ||
import { createDb } from '../utils/create-db'; | ||
|
||
describe('Add Track To Queue', () => { | ||
let app: INestApplication; | ||
let slack: jest.Mocked<SlackTestingService>; | ||
let trackDataService: jest.Mocked<TrackDataService>; | ||
let trackService: jest.Mocked<TrackService>; | ||
let userDataService: jest.Mocked<UserDataService>; | ||
|
||
beforeAll(async () => { | ||
process.env.DB_DATABASE = 'sdj_test_add_track_to_queue'; | ||
jest.setTimeout(30 * 1000); | ||
await createDb(); | ||
|
||
const module = await Test.createTestingModule({ | ||
imports: [WebSocketModule, SlackModule, BackendSharedTestingKernelModule], | ||
}) | ||
.overrideProvider(UserDataService) | ||
.useValue({ getUserData: jest.fn() }) | ||
.overrideProvider(TrackDataService) | ||
.useValue({ loadTrackData: jest.fn() }) | ||
.overrideProvider(TrackService) | ||
.useValue({ download: jest.fn(), getDuration: jest.fn() }) | ||
.compile(); | ||
app = module.createNestApplication(); | ||
slack = module.get(SlackService); | ||
trackDataService = module.get(TrackDataService); | ||
trackService = module.get(TrackService); | ||
userDataService = module.get(UserDataService); | ||
await app.init(); | ||
}); | ||
|
||
test('saves track, channel, user and queued track in database', (done) => { | ||
userDataService.getUserData.mockResolvedValue({ | ||
user: '1234', | ||
name: 'Maciej', | ||
profile: { display_name: 'Maciek', real_name: 'Maciej Sikorski' }, | ||
}); | ||
slack.fakeReceiveMessage('message', { | ||
type: 'message', | ||
channel: 'abc', | ||
user: '1234', | ||
text: 'play <https://www.youtube.com/watch?v=G8dsvclf3Tk>', | ||
} as any); | ||
trackDataService.loadTrackData.mockResolvedValue({ | ||
title: 'Title', | ||
duration: 4 * 60 * 1000, | ||
}); | ||
trackService.download.mockResolvedValue('some-path.mp3'); | ||
trackService.getDuration.mockResolvedValue(4 * 60 * 1000); | ||
setTimeout(async () => { | ||
expect(await getRepository(User).findOneOrFail('1234')).toBeTruthy(); | ||
expect(await getRepository(Channel).findOneOrFail('abc')).toBeTruthy(); | ||
expect(await getRepository(QueuedTrack).findOneOrFail(1)).toBeTruthy(); | ||
expect( | ||
await getRepository(Track).findOneOrFail('G8dsvclf3Tk') | ||
).toBeTruthy(); | ||
done(); | ||
}, 5 * 1000); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.