Bingo for–refactor web service with tests–part 18


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 . Those are my blog posts for Bingo : ( scroll below for the post)
1Create meeting
2Create Tests
3Finalize Create meeting
4Sharing meeting
5Keep Score
6Add obsolete
7Finalizing obsolete
8End meeting
9Dockerize tests
10Azure CI tests
11Yarn workspaces
13Intermezzo - CLI improvements
14typescript compile run with node
15NestJS ,swagger and create a meeting
16Finalizing API
17Intermezzo - jest vs jasmine error
18Refactor WebAPI and test service
19Heroku Deploy NestJs
21Deploy Angular to GitHub
22WebAPI and Web
24Documentation of the code

In the same manner that we refactor the objects, we have now to refactor the service that is called by the WebAPI. Yes, we have the skinny controllers concept – but the service is something new for the application. Think about retrieving the list of the meetings  – this is something that we did not need in the console application( it was just the current meeting)

So how to test ? The easy way is to put the service ( with the dependencies) in a new project –  bingo-cards-api-objects. Then reference the project from bingo-cards-api nestjs webAPI – and ensure it works. Now it is the time for tests:

describe("Meetings API service creation", () => {
    it("a meeting should have been created properly ", async () => {
        const ms: MeetingService =new MeetingService();
        const userName:string = "Andrei";
        const meetingName:string = "Meeting today"
        const m:Meeting =await  ms.create(userName,meetingName);
      it("a meeting should have been retrieved properly ", async () => {
        const ms: MeetingService =new MeetingService();
        const userName:string = "Andrei";
        const meetingName:string = "Meeting today"
        const m :Meeting=await  ms.create(userName,meetingName);
        const retr :ActualMeeting[]= ms.ActualMeetings();




And that is not all. As the code for checkCard look , it should be more tests….

public checkCard(idMeeting: any, idCard: number, nameParticipant: string ): Meeting{
        const m = this.meetings.find(it => it.Id === idMeeting );
        // TODO: throw if meeting is null
        const c = m.FindCard(idCard);
        // TODO: throw if card is null
        const p = m.FindParticipantAfterName(nameParticipant);
        // TODO: throw if participant is null

        m.CheckCardByParticipant(c, p);
        return m;


Not that I have time for this…