Bingo for–refactor web service with tests–part 18

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)
NrLink
1Create meeting
2Create Tests
3Finalize Create meeting
4Sharing meeting
5Keep Score
6Add obsolete
7Finalizing obsolete
8End meeting
9Dockerize tests
10Azure CI tests
11Yarn workspaces
12CLI
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
20Angular
21Deploy Angular to GitHub
22WebAPI and Web
23Documentation
24Documentation of the code
25Conclusions

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);
        expect(m.Name).toBe(meetingName);
        expect(m.Participants.length).toBe(1);
        expect(m.Participants[0].Name).toBe(userName);
      });
      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();

        expect(retr.length).toBe(1);

        expect(retr[0].idMeeting).toBe(m.Id);
        expect(retr[0].participantName).toBe(userName);

      });
  });

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…