From 82f97da82b8ba53436fd1776ceb4b952184bf0f3 Mon Sep 17 00:00:00 2001 From: majean5 Date: Mon, 21 Nov 2022 15:06:49 +0100 Subject: [PATCH] corrections classes et unit tests ajout id sur Conversation et Message --- bob_party/src/core/conversation.ts | 9 ++++++++- bob_party/src/core/message.ts | 9 ++++++++- bob_party/src/core/tests/conversation.test.ts | 17 ++++++++++------- bob_party/src/core/tests/message.test.ts | 5 ++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/bob_party/src/core/conversation.ts b/bob_party/src/core/conversation.ts index 522e866..5d4eed3 100644 --- a/bob_party/src/core/conversation.ts +++ b/bob_party/src/core/conversation.ts @@ -3,12 +3,14 @@ import { User } from "./User/user"; export class Conversation{ + private Id: string; private tabUser: User[]; private tabMessage: Message[]; private name: string; /* Constructor of the class */ - constructor(tabUser: User[], tabMessage:Message[], name:string){ + constructor(id: string, tabUser: User[], tabMessage:Message[], name:string){ + this.Id=id; this.tabUser=[...tabUser]; this.tabMessage=[...tabMessage]; this.name=name; @@ -36,6 +38,11 @@ export class Conversation{ this.sortMessageDesc(); } + /* Brief : function returning the id of a conversation */ + getId(){ + return this.Id; + } + /* Brief : function returning the name to a conversation */ getName(){ return this.name; diff --git a/bob_party/src/core/message.ts b/bob_party/src/core/message.ts index 57ba52a..087833d 100644 --- a/bob_party/src/core/message.ts +++ b/bob_party/src/core/message.ts @@ -2,12 +2,14 @@ import { User } from './User/user' export class Message{ + private Id: string; private Content: string; private Sender: User; private DateEnvoie: Date; /* Constructor of the class */ - constructor(content: string, sender:User, dateEnvoie:Date){ + constructor(id: string, content: string, sender:User, dateEnvoie:Date){ + this.Id=id; this.Content=content; this.Sender=sender; this.DateEnvoie=dateEnvoie; @@ -28,6 +30,11 @@ export class Message{ this.DateEnvoie=dateEnvoie; } + /* Brief : Function getting the id of a message */ + getMessageId(){ + return this.Id; + } + /* Brief : Function getting the content of a message */ getMessageContent(){ return this.Content; diff --git a/bob_party/src/core/tests/conversation.test.ts b/bob_party/src/core/tests/conversation.test.ts index c010c76..c7ea9be 100644 --- a/bob_party/src/core/tests/conversation.test.ts +++ b/bob_party/src/core/tests/conversation.test.ts @@ -15,26 +15,29 @@ let usr2 = new User('00002', 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8 let theDate = new Date(2022,10,14); let theDate2 = new Date(2022,10,13); let theDate3 = new Date(2022,10,15); -let mess = new Message('Bob Party est le meilleur projet', usr, theDate2); +let mess = new Message('M0001', 'Bob Party est le meilleur projet', usr, theDate2); let tabU:User[] = [usr, usr2]; -let mess2 = new Message('Oui tout à fait', usr2, theDate); -let mess3 = new Message('Mais oui trop de ouf', usr, theDate3); +let mess2 = new Message('M0002', 'Oui tout à fait', usr2, theDate); +let mess3 = new Message('M0003', 'Mais oui trop de ouf', usr, theDate3); let tabM:Message[] = [mess, mess2]; -let convo = new Conversation(tabU, tabM, 'the conv'); +let convo = new Conversation('C0001', tabU, tabM, 'the conv'); let usr3 = new User('00003', 'wow', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab); // Get tests describe('Conversation get tests', () => { + it('should return C0001', () => { + expect(convo.getId()).toBe('C0001'); + }) + it('should return the conv', () => { + expect(convo.getName()).toBe('the conv'); + }) it('should return tabU [usr, usr2] (users)', () => { expect(convo.getTabUser()).toBe(tabU); }) it('should return tabM [mess, mess2] (messages)', () => { expect(convo.getTabMessage()).toBe(tabM); }) - it('should return the conv', () => { - expect(convo.getName()).toBe('the conv'); - }) it('should return Oui tout à fait (mess2)', () => { expect(convo.getLastMessage()).toBe('Oui tout à fait'); }) diff --git a/bob_party/src/core/tests/message.test.ts b/bob_party/src/core/tests/message.test.ts index 7d16675..63bbba3 100644 --- a/bob_party/src/core/tests/message.test.ts +++ b/bob_party/src/core/tests/message.test.ts @@ -12,11 +12,14 @@ let usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, let usr2 = new User('00002', 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab); let theDate = new Date(2022,10,14); let theDate2 = new Date(2022,10,13); -let mess = new Message('Bob Party est le meilleur projet', usr, theDate); +let mess = new Message('M0001', 'Bob Party est le meilleur projet', usr, theDate); // Get tests describe('Message get tests', () => { + it('should return M0001', () => { + expect(mess.getMessageId()).toBe('M0001'); + }) it('should return Bob Party est le meilleur projet', () => { expect(mess.getMessageContent()).toBe('Bob Party est le meilleur projet'); })