From 03e24e051489f0a1822adb581c76dc0e02bac993 Mon Sep 17 00:00:00 2001 From: majean5 Date: Tue, 22 Nov 2022 13:56:11 +0100 Subject: [PATCH] suite tests unitaires --- .../src/services/tests/loaderUserApi.test.ts | 27 ++++++++++++++++++- bob_party/src/services/tests/stubUser.test.ts | 22 +++++++++++++++ bob_party/src/services/userServices/stub.ts | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 bob_party/src/services/tests/stubUser.test.ts diff --git a/bob_party/src/services/tests/loaderUserApi.test.ts b/bob_party/src/services/tests/loaderUserApi.test.ts index 9cbfaec..ad5a6ab 100644 --- a/bob_party/src/services/tests/loaderUserApi.test.ts +++ b/bob_party/src/services/tests/loaderUserApi.test.ts @@ -4,6 +4,7 @@ import { Match } from '../../core/match'; import { MatchSolo } from '../../core/matchSolo'; import { GameSolo } from '../../core/gameSolo'; import tabUS from '../../constUser'; +import { Conversation } from '../../core/conversation'; // Instances let loader:ILoaderUser = new LoaderUserApi(); @@ -15,10 +16,19 @@ let map = new Map([ ]); let game:GameSolo = new GameSolo('G0001', 'SuperJeu', require('id'), 'source', 1, 1, map); let match:Match = new MatchSolo('M0001', tabUS, game); +let convo:Conversation = new Conversation(tabUS, [], 'superConvo'); + // Tests describe('LoaderUserApi tests', () => { - describe('loadById Tests', () => { + /* + describe('loadAllUser tests', () => { + it('should return tabUS [UserTest, Alban, UserActu, Fefe63]', () => { + expect(loader.loadAllUser()).toEqual(tabUS); + }) + }) + */ + describe('loadById tests', () => { it('should return UserTest (id: 48)', () => { expect(loader.loadByID('48')).toEqual(tabUS[0]); }) @@ -46,5 +56,20 @@ describe('LoaderUserApi tests', () => { it('should return UserTest', () => { expect(loader.loadUserByMatch(match)).toEqual(tabUS[0]); }) + it('should return null', () => { + expect(loader.loadByUsernamePassword('jExistePas', 'jExistePas')).toEqual(null); + }) + }) + describe('loadUserByConversation tests', () => { + it('should return tabUS', () => { + expect(loader.loadUserByConversation(convo)).toEqual(tabUS); + }) + }) + /* + describe('loadLastId', () => { + it('should return U0004', () => { + expect(loader.loadLastId()).toBe('U0004'); + }) }) + */ }) \ No newline at end of file diff --git a/bob_party/src/services/tests/stubUser.test.ts b/bob_party/src/services/tests/stubUser.test.ts new file mode 100644 index 0000000..7893f40 --- /dev/null +++ b/bob_party/src/services/tests/stubUser.test.ts @@ -0,0 +1,22 @@ +import StubUser from '../userServices/stub'; +import { User } from '../../core/User/user'; +import { Skin } from '../../core/skin'; + +// Instances +let stub:StubUser = new StubUser(); +let tabUS:User[] = [ + new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), + new User("48", "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), + new User("17", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)],), + new User("17", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), +]; + + +// Tests +describe('StubUser tests', () => { + describe('loadAllUser tests', () => { + it('should return tabUS', () => { + expect(stub.loadAllUser()).toEqual(tabUS); + }) + }) +}) \ No newline at end of file diff --git a/bob_party/src/services/userServices/stub.ts b/bob_party/src/services/userServices/stub.ts index b654e81..0964176 100644 --- a/bob_party/src/services/userServices/stub.ts +++ b/bob_party/src/services/userServices/stub.ts @@ -6,7 +6,7 @@ import ILoaderUser from "./ILoaderUser"; export default class StubUser implements ILoaderUser{ - tabUS:User[]=[ + private tabUS:User[]=[ new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), new User("48", "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), new User("17", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)],),