Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getEvents method name unclear #15

Open
georgesbiaux opened this issue Aug 30, 2021 · 0 comments · May be fixed by #33
Open

getEvents method name unclear #15

georgesbiaux opened this issue Aug 30, 2021 · 0 comments · May be fixed by #33

Comments

@georgesbiaux
Copy link

Hi :)

I have used the lib in a use case when several events are sent to EventBridge, I thought that the getEvents method would fetch them all (until the queue was empty). But instead, it only fetched the messages one by one. This was quite confusing since the plural in the name of the method lead me to think it would fetch all the events fired so far. This confusion caused many failure in my test suite, which were difficult to debug.

So, in the end, I implemented a method like so to fetch all events in one function call:

  static async getAllEventBridgeMessages(): Promise<EventBridgeMessage[]> {
    if (EventBridgeTestUtil.eventBridge === null) {
      throw new Error("EventBridgeTestUtil has not been setup");
    }

    let result: EventBridgeMessage[] = [];
    let lastResults: EventBridgeMessage[] = [];

    do {
      try {
        const events = await EventBridgeTestUtil.eventBridge.getEvents();
        lastResults = events.Messages;
        result = [...result, ...lastResults];
      } catch (e) {
        lastResults = [];
      }
    } while (lastResults.length !== 0);

    return result;
  }

It would be great if getEvents could be renamed to be clearer, such as getEvent and if a method getAllEvents could be implemented :)

Thanks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant