diff --git a/src/app.module.ts b/src/app.module.ts index 5fd39cd..0b8278e 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -56,7 +56,7 @@ dotenv.config(); BANTR_STEAM_API: Joi.string().required(), BANTR_FACEIT_MATCH_CRON: Joi.string().default('0 */2 * * *'), BANTR_STEAM_BANS_CRON: Joi.string().default('0 */2 * * *'), - BANTR_STEAM_MATCH_CRON: Joi.string().default('0 */2 * * *'), + BANTR_STEAM_MATCH_CRON: Joi.string().default('0 * * * *'), BANTR_DISCORD_BOT_TOKEN: Joi.string(), BANTR_GLOBAL_NOTIFICATION_DISCORD: Joi.string().default(''), BANTR_DEMO_DOWNLOAD_LOCATION: Joi.string().default('tmp/'), diff --git a/src/ban/ban.service.spec.ts b/src/ban/ban.service.spec.ts index dfd14ff..391c3ed 100644 --- a/src/ban/ban.service.spec.ts +++ b/src/ban/ban.service.spec.ts @@ -7,7 +7,8 @@ import { NotificationService } from '../notification/notification.service'; import Player from '../player/player.entity'; import { PlayerService } from '../player/player.service'; import { QueueService } from '../queue/queue.service'; -import { EconomyBan, SteamService } from '../steam/steam.service'; +import { EconomyBan } from '../steam/interface/IGetPlayerBansResponse.interface'; +import { SteamService } from '../steam/steam.service'; import { BanRepository } from './ban.repository'; import { BanService } from './ban.service'; diff --git a/src/ban/ban.service.ts b/src/ban/ban.service.ts index b25689b..5a96ff5 100644 --- a/src/ban/ban.service.ts +++ b/src/ban/ban.service.ts @@ -4,13 +4,11 @@ import { Injectable, Logger } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Queue } from 'bull'; import Player from 'src/player/player.entity'; -import IGetPlayerBansResponse, { - EconomyBan -} from 'src/steam/interface/IGetPlayerBansResponse.interface'; import { NotificationService } from '../notification/notification.service'; import { PlayerService } from '../player/player.service'; import { QueueService } from '../queue/queue.service'; +import IGetPlayerBansResponse, { EconomyBan } from '../steam/interface/IGetPlayerBansResponse.interface'; import { SteamService } from '../steam/steam.service'; import Ban from './ban.entity'; import { BanRepository } from './ban.repository'; diff --git a/src/faceit/faceit.service.spec.ts b/src/faceit/faceit.service.spec.ts index 6fd57c3..50732a8 100644 --- a/src/faceit/faceit.service.spec.ts +++ b/src/faceit/faceit.service.spec.ts @@ -21,8 +21,8 @@ const talkbackServer = talkback({ port: 7456, path: `${__dirname}/tapes`, ignoreHeaders: ['authorization'], + silent: true, tapeNameGenerator: (tapeNumber, tape) => { - // TODO: This might fail on Windows... return path.join(`${tape.req.method}`, `-${tape.req.url}`); } }); @@ -72,7 +72,7 @@ describe('FaceitService', () => { userRepository = await module.get(UserRepository); httpService = await module.get(HttpService); configService = await module.get(ConfigService); - matchService = await module.get(FaceitService); + matchService = await module.get(MatchService); // Override the private method and supply it with our proxy server service['getFaceItApiUrl'] = () => 'http://localhost:7456'; diff --git a/src/match/match.service.ts b/src/match/match.service.ts index c2c5cd5..4e8dedb 100644 --- a/src/match/match.service.ts +++ b/src/match/match.service.ts @@ -1,5 +1,5 @@ import { OnQueueCompleted, OnQueueError, OnQueueFailed, OnQueueProgress, Process, Processor } from '@nestjs/bull'; -import { HttpService, Injectable, Logger } from '@nestjs/common'; +import { forwardRef, HttpService, Inject, Injectable, Logger } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { InjectRepository } from '@nestjs/typeorm'; import * as Sentry from '@sentry/node'; @@ -48,6 +48,7 @@ export class MatchService { private userRepository: UserRepository, private readonly httpService: HttpService, private queueService: QueueService, + @Inject(forwardRef(() => PlayerService)) private playerService: PlayerService, private readonly config: ConfigService, private connection: Connection diff --git a/src/steam/steam.module.ts b/src/steam/steam.module.ts index dce5ec0..dbc1673 100644 --- a/src/steam/steam.module.ts +++ b/src/steam/steam.module.ts @@ -1,15 +1,15 @@ -import { HttpModule, Module } from '@nestjs/common'; +import { forwardRef, HttpModule, Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { UserRepository } from 'src/user/user.repository'; +import { MatchModule } from '../match/match.module'; +import { UserRepository } from '../user/user.repository'; import { SteamService } from './steam.service'; -import { MatchModule } from 'src/match/match.module'; @Module({ imports: [ TypeOrmModule.forFeature([UserRepository]), HttpModule, - MatchModule + forwardRef(() => MatchModule) ], providers: [SteamService], exports: [SteamService] diff --git a/src/steam/steam.service.spec.ts b/src/steam/steam.service.spec.ts index f4d201c..c9e3d18 100644 --- a/src/steam/steam.service.spec.ts +++ b/src/steam/steam.service.spec.ts @@ -2,34 +2,143 @@ import { HttpService } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Test, TestingModule } from '@nestjs/testing'; +import * as dotenv from 'dotenv'; +import * as path from 'path'; +import { mockUser } from '../../test/globals'; +import { MatchService } from '../match/match.service'; +import { UserRepository } from '../user/user.repository'; import { SteamService } from './steam.service'; +import SteamBot from './SteamBot'; -const mockHttpService = () => ({}); +jest.mock('./SteamBot'); + +dotenv.config(); +const mockHttpService = new HttpService(); const mockConfigService = () => ({ - get: jest.fn() + get: jest.fn(() => process.env.BANTR_STEAM_API) +}); + +//eslint-disable-next-line @typescript-eslint/no-var-requires +const talkback = require('talkback'); + +const talkbackServer = talkback({ + host: 'https://api.steampowered.com', + record: talkback.Options.RecordMode.NEW, + port: 7457, + silent: true, + path: `${__dirname}/tapes`, + ignoreQueryParams: ['key', 'steamidkey'], + tapeNameGenerator: (tapeNumber, tape) => { + return path.join(`${tape.req.method}`, `-${tape.req.url}`); + } +}); + +const mockedUser = mockUser({}); + +const mockUserRepository = () => ({ + getUsersSortedByLastChecked: jest.fn().mockReturnValue([mockedUser]) }); +const mockMatchService = { + addMatchToQueue: jest.fn() +}; + +/** + * This is a bit of a weird method, + * but had trouble getting the TestingModule to initialize a real SteamService + * Something to do with circular dependency I think... + * This works for now, it's just a test :) + */ +const testService = new SteamService( + (mockUserRepository() as unknown) as UserRepository, + mockHttpService, + (mockConfigService() as unknown) as ConfigService, + (mockMatchService as unknown) as MatchService +); + describe('SteamService', () => { let service: SteamService; let httpService; let configService; + let matchService: MatchService; + let userRepository; + + beforeAll(() => { + talkbackServer.start(); + }); + + afterAll(() => { + talkbackServer.close(); + }); beforeEach(async () => { + jest.clearAllMocks(); const module: TestingModule = await Test.createTestingModule({ - providers: [SteamService, - { provide: HttpService, useFactory: mockHttpService }, + providers: [ + { provide: SteamService, useValue: testService }, + { provide: UserRepository, useFactory: mockUserRepository }, + { provide: HttpService, useValue: mockHttpService }, + { provide: MatchService, useValue: mockMatchService }, { provide: ConfigService, useFactory: mockConfigService } ] }).compile(); - service = module.get(SteamService); + userRepository = await module.get(UserRepository); + matchService = await module.get(MatchService); + service = await module.get(SteamService); httpService = module.get(HttpService); configService = module.get(ConfigService); + + // Override the private method and supply it with our proxy server + service['getSteamApiUrl'] = () => 'http://localhost:7457'; }); it('should be defined', () => { expect(service).toBeDefined(); }); + + it('Does not start a Steam bot when no auth credentials are provided', async () => { + expect(service.SteamBot).toBeUndefined; + }); + + describe('Getting matchmaking matches from steam', () => { + beforeEach(() => { + // This is mocked + service['SteamBot'] = new SteamBot('user', 'password'); + mockedUser.settings.lastKnownMatch = 'CSGO-nvYA4-FkWRA-dp8AK-qLFot-7WFuA'; + }); + + it('Gets new matches until there are no new ones and adds them to the match queue', async () => { + const addToQueueSpy = jest.spyOn(matchService, 'addMatchToQueue'); + const getDemoUrlFromShareCodeSpy = jest.spyOn( + service.SteamBot, + 'getDemoUrlFromShareCode' + ); + await service.getMatchesForUsers(); + + // In the tapes, there's 7 valid matches + expect(getDemoUrlFromShareCodeSpy).toHaveBeenCalledTimes(7); + expect(addToQueueSpy).toHaveBeenCalledTimes(7); + }); + + it('Does not throw when Steam bot is not running', async () => { + const addToQueueSpy = jest.spyOn(matchService, 'addMatchToQueue'); + + service['SteamBot'] = undefined; + await service.getMatchesForUsers(); + + expect(addToQueueSpy).toHaveBeenCalledTimes(0); + }); + + it('Updates the lastKnownCode for a user after getting matches', async () => { + await service.getMatchesForUsers(); + + expect(mockedUser.settings.lastKnownMatch).toBe( + 'CSGO-wkzOw-RzsHo-AXBL7-tLzdR-rvMpP' + ); + expect(mockedUser.settings.save).toHaveBeenCalledTimes(1); + }); + }); }); diff --git a/src/steam/steam.service.ts b/src/steam/steam.service.ts index be711b2..340d17a 100644 --- a/src/steam/steam.service.ts +++ b/src/steam/steam.service.ts @@ -1,23 +1,18 @@ import { User } from '@bantr/lib/dist/entities'; -import { - OnQueueCompleted, - OnQueueError, - OnQueueFailed, - Process, - Processor -} from '@nestjs/bull'; +import { IMatchType } from '@bantr/lib/dist/types'; +import { OnQueueCompleted, OnQueueError, OnQueueFailed, Process, Processor } from '@nestjs/bull'; import { HttpService, Injectable, Logger } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { InjectRepository } from '@nestjs/typeorm'; import * as Sentry from '@sentry/node'; import { Job } from 'bull'; -import { LastCheckedType, UserRepository } from 'src/user/user.repository'; -import SteamBot from './SteamBot'; +import { CsgoMatchDto } from '../match/dto/csgoMatch.dto'; +import { MatchService } from '../match/match.service'; +import { LastCheckedType, UserRepository } from '../user/user.repository'; import IGetPlayerBansResponse from './interface/IGetPlayerBansResponse.interface'; -import { CsgoMatchDto } from 'src/match/dto/csgoMatch.dto'; -import { IMatchType } from '@bantr/lib/dist/types'; -import { MatchService } from 'src/match/match.service'; +import SteamBot from './SteamBot'; + /** * Handles actions to do with Steam */ @@ -33,7 +28,7 @@ export class SteamService { */ private steamApiKey: string; - private SteamBot: SteamBot; + SteamBot: SteamBot; /** * The service constructor @@ -48,28 +43,35 @@ export class SteamService { private readonly matchService: MatchService ) { this.steamApiKey = configService.get('BANTR_STEAM_API'); - this.SteamBot = new SteamBot( - configService.get('BANTR_STEAM_BOT_USERNAME'), + + if ( + configService.get('BANTR_STEAM_BOT_USERNAME') && configService.get('BANTR_STEAM_BOT_PASSWORD') - ); + ) { + this.SteamBot = new SteamBot( + configService.get('BANTR_STEAM_BOT_USERNAME'), + configService.get('BANTR_STEAM_BOT_PASSWORD') + ); + } } @Process({ name: '__default__' }) async getMatchesForUsers(): Promise { + if (!this.SteamBot) { + this.logger.warn( + 'There are no Steam credentials configured, Steam bot is not active and we cannot get new demos from Steam matchmaking' + ); + return; + } + this.logger.log(`Checking for new Matchmaking matches`); const users = await this.userRepository.getUsersSortedByLastChecked( LastCheckedType.steam ); for (const user of users) { - let apiResponses: Array; - try { - apiResponses = await this.getNewMatchesForUser(user); - } catch (e) { - this.logger.error(e); - continue; - } - + const apiResponses = await this.getNewMatchesForUser(user); + user.settings.save(); for (const shareCode of apiResponses) { const match = new CsgoMatchDto(); match.externalId = shareCode; @@ -81,6 +83,10 @@ export class SteamService { } } + private getSteamApiUrl() { + return 'https://api.steampowered.com'; + } + /** * Get ban status for an array of steam IDs * @param steamIds @@ -88,7 +94,7 @@ export class SteamService { async getUserBans(steamIds: string[]) { // TODO: create interface for steamId const response = await this.httpService - .get(`https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/`, { + .get(`${this.getSteamApiUrl()}/ISteamUser/GetPlayerBans/v1/`, { params: { key: this.steamApiKey, steamids: steamIds.join(',') @@ -106,7 +112,7 @@ export class SteamService { async getUserProfiles(steamIds: string[]) { // TODO: create interface for steamId const response = await this.httpService - .get(`https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/`, { + .get(`${this.getSteamApiUrl()}/ISteamUser/GetPlayerSummaries/v2/`, { params: { key: this.steamApiKey, steamids: steamIds.join(',') @@ -125,7 +131,7 @@ export class SteamService { ); const response = await this.httpService .get( - `https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?`, + `${this.getSteamApiUrl()}/ICSGOPlayers_730/GetNextMatchSharingCode/v1?`, { params: { key: this.steamApiKey, diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-A4Ft9-BT7yZ-XLOeK-QtvW8-ZeQ3A.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-A4Ft9-BT7yZ-XLOeK-QtvW8-ZeQ3A.json5 new file mode 100644 index 0000000..471ae21 --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-A4Ft9-BT7yZ-XLOeK-QtvW8-ZeQ3A.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:06.340Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-A4Ft9-BT7yZ-XLOeK-QtvW8-ZeQ3A', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 200, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:06 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:06 GMT', + ], + 'content-length': [ + '70', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'CSGO-zyMkH-EyueP-K4yBk-oWwiK-OSveM', + }, + }, + }, +} \ No newline at end of file diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-D9KjT-M9t99-hX7WB-Q9tSv-vMUSH.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-D9KjT-M9t99-hX7WB-Q9tSv-vMUSH.json5 new file mode 100644 index 0000000..37787bd --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-D9KjT-M9t99-hX7WB-Q9tSv-vMUSH.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:07.102Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-D9KjT-M9t99-hX7WB-Q9tSv-vMUSH', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 200, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:07 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:07 GMT', + ], + 'content-length': [ + '70', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'CSGO-DNLpG-iNmqM-i9uMV-F6rwJ-Z9JjC', + }, + }, + }, +} \ No newline at end of file diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-DNLpG-iNmqM-i9uMV-F6rwJ-Z9JjC.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-DNLpG-iNmqM-i9uMV-F6rwJ-Z9JjC.json5 new file mode 100644 index 0000000..ec731df --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-DNLpG-iNmqM-i9uMV-F6rwJ-Z9JjC.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:07.457Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-DNLpG-iNmqM-i9uMV-F6rwJ-Z9JjC', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 200, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:07 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:07 GMT', + ], + 'content-length': [ + '70', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'CSGO-wkzOw-RzsHo-AXBL7-tLzdR-rvMpP', + }, + }, + }, +} \ No newline at end of file diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-d585r-SHvkJ-LPPsA-ykmM5-OqTiA.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-d585r-SHvkJ-LPPsA-ykmM5-OqTiA.json5 new file mode 100644 index 0000000..903b197 --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-d585r-SHvkJ-LPPsA-ykmM5-OqTiA.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:05.711Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-d585r-SHvkJ-LPPsA-ykmM5-OqTiA', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 200, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:05 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:06 GMT', + ], + 'content-length': [ + '70', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'CSGO-qux5L-SpTEy-2YmHd-EdL3A-udTnB', + }, + }, + }, +} \ No newline at end of file diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-nvYA4-FkWRA-dp8AK-qLFot-7WFuA.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-nvYA4-FkWRA-dp8AK-qLFot-7WFuA.json5 new file mode 100644 index 0000000..742cc14 --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-nvYA4-FkWRA-dp8AK-qLFot-7WFuA.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:05.317Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-nvYA4-FkWRA-dp8AK-qLFot-7WFuA', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 200, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:05 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:05 GMT', + ], + 'content-length': [ + '70', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'CSGO-d585r-SHvkJ-LPPsA-ykmM5-OqTiA', + }, + }, + }, +} \ No newline at end of file diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-qux5L-SpTEy-2YmHd-EdL3A-udTnB.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-qux5L-SpTEy-2YmHd-EdL3A-udTnB.json5 new file mode 100644 index 0000000..d5f21ed --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-qux5L-SpTEy-2YmHd-EdL3A-udTnB.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:06.046Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-qux5L-SpTEy-2YmHd-EdL3A-udTnB', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 200, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:06 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:06 GMT', + ], + 'content-length': [ + '70', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'CSGO-A4Ft9-BT7yZ-XLOeK-QtvW8-ZeQ3A', + }, + }, + }, +} \ No newline at end of file diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-wkzOw-RzsHo-AXBL7-tLzdR-rvMpP.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-wkzOw-RzsHo-AXBL7-tLzdR-rvMpP.json5 new file mode 100644 index 0000000..89e3214 --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-wkzOw-RzsHo-AXBL7-tLzdR-rvMpP.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:07.846Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-wkzOw-RzsHo-AXBL7-tLzdR-rvMpP', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 202, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + 'content-length': [ + '39', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:08 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:08 GMT', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'n/a', + }, + }, + }, +} \ No newline at end of file diff --git a/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-zyMkH-EyueP-K4yBk-oWwiK-OSveM.json5 b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-zyMkH-EyueP-K4yBk-oWwiK-OSveM.json5 new file mode 100644 index 0000000..b57c358 --- /dev/null +++ b/src/steam/tapes/GET/-/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-zyMkH-EyueP-K4yBk-oWwiK-OSveM.json5 @@ -0,0 +1,42 @@ +{ + meta: { + createdAt: '2020-07-25T18:54:06.718Z', + host: 'https://api.steampowered.com', + resHumanReadable: true, + }, + req: { + url: '/ICSGOPlayers_730/GetNextMatchSharingCode/v1?steamid=76561198028175941&knowncode=CSGO-zyMkH-EyueP-K4yBk-oWwiK-OSveM', + method: 'GET', + headers: { + accept: 'application/json, text/plain, */*', + 'user-agent': 'axios/0.19.2', + connection: 'close', + }, + body: '', + }, + res: { + status: 200, + headers: { + 'content-type': [ + 'application/json; charset=UTF-8', + ], + expires: [ + 'Sat, 25 Jul 2020 18:55:06 GMT', + ], + date: [ + 'Sat, 25 Jul 2020 18:54:07 GMT', + ], + 'content-length': [ + '70', + ], + connection: [ + 'close', + ], + }, + body: { + result: { + nextcode: 'CSGO-D9KjT-M9t99-hX7WB-Q9tSv-vMUSH', + }, + }, + }, +} \ No newline at end of file diff --git a/test/globals.ts b/test/globals.ts index e4274ea..8bdf670 100644 --- a/test/globals.ts +++ b/test/globals.ts @@ -2,7 +2,7 @@ import { Ban, User, UserSettings } from '@bantr/lib/dist/entities'; import { Player } from '@bantr/lib/dist/entities/player.entity'; import * as faker from 'faker'; -import { EconomyBan, IGetPlayerBansResponse } from '../src/steam/steam.service'; +import IGetPlayerBansResponse, { EconomyBan } from '../src/steam/interface/IGetPlayerBansResponse.interface'; export function mockUser(options: IMockUserOptions): User { const user = new User(); @@ -21,6 +21,9 @@ export function mockUser(options: IMockUserOptions): User { user.settings.notificationCommunityEnabled = true; user.settings.notificationEconomyEnabled = true; user.settings.notificationFaceitEnabled = true; + user.settings.lastKnownMatch = 'CSGO-nvYA4-FkWRA-dp8AK-qLFot-7WFuA'; + user.settings.matchAuthCode = '6CSJ-PZ6D7-8PAL'; + user.settings.save = jest.fn(); return user; }