Bingo for meetings–hide results–part 8
Bingo
Bingo is a small project, written in TypeScript , and developed with Alexandru Badita in launch break (one hour - more or less). You can find sources at https://github.com/alexandru360/PresentationBingoCards/ . Those are my blog posts for Bingo : ( scroll below for the post)The last requirement says
EndMeeting:
The score of how many cards/ what cards were checked will be available 1 hour and 5 minutes
We have already done something similar when the meeting was considered obsolete – we decided to not throw error, but use
Result< T, Error> . So I supposed to be easy …. However, it was not. Because we are modifying the results of the functions, we are supposed to modify also the tests….
First , then modification of the code. Because of the refactoring, the AllUnchecked function calls TotalNumberOfCardsChecked.
public TotalNumberOfCardsChecked():number{ return this.Cards.filter(it=>it.IsChecked()).length ; } public AllUnchecked(): boolean{ return (this.TotalNumberOfCardsChecked() === 0); }
Now, because we cannot TotalNumberOfCardsChecked returns Result<number, Error> , the function AllUnchecked must be re-written :
public TotalNumberOfCardsChecked():Result<number, Error>{ if(this.CanSeeScore()){ return ok(this.Cards.filter(it=>it.IsChecked()).length ); } else{ //TODO :Make a proper error return err(new Error(`cannot see score for ${this.Id}`)); } } public AllUnchecked(): Result< boolean, Error>{ var res=this.TotalNumberOfCardsChecked(); console.log(" all unchecked" + res.isOk()); return res.andThen(it=> ok(it===0)); // const ret= res.match( // (v)=>{return ok(v==0)}, // (error)=>{ return error} // ); // return ret; }
Second , the test will fail. Take “card should be checked” – original code was pretty easy
import MeetingsFactory from '../MeetingsFactory'; import Meeting from '../meeting'; describe('Check card basic', () => { it('card should be checked', () => { const mf=new MeetingsFactory(); const m1=mf.CreateMeeting("andrei","first meeting"); console.log(m1.Cards.length); expect(m1.AllUnchecked()).toBe(true); m1.CheckCard(m1.Cards[0], m1.Participants[0]); expect(m1.AllUnchecked()).toBe(false); expect(m1.IsCardCheckedByParticipant(m1.Cards[0], m1.Participants[0])).toBe(true); }) })
Now it is
it('card should be checked', () => { const mf=new MeetingsFactory(); const m1=mf.CreateMeeting("andrei","first meeting"); console.log(m1.Cards.length); let res=m1.AllUnchecked(); expect(res.isOk()).toBe(true); let result= false; res.map(t=> result =t); expect(result).toBe(true); let res1 = m1.CheckCardByParticipant(m1.Cards[0], m1.Participants[0]); expect(res1.isOk()).toBe(true); res=m1.AllUnchecked(); expect(res.isOk()).toBe(true); result= false; res.map(t=> result =t); expect(result).toBe(false); expect(m1.IsCardCheckedByParticipant(m1.Cards[0], m1.Participants[0]).isOk()).toBe(true); })
Leave a Reply