Get User Events
Explore how to retrieve user-specific events from an API and integrate them into a dashboard calendar in Angular. Learn to write tests for successful and failed API calls, use HttpTestingController for mocking, and update your component with event data based on the current user.
We'll cover the following...
It’s time to display new events on the user dashboard. We’ll display these within a calendar using a library that we’ll set up later in this chapter.
Below is our updated code. Use this to make further changes:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>LetsGetLunch</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> </head> <body> <app-root></app-root> </body> </html>
Tests for getUserEvents
First we need to associate all events with a given user. View the documentation for this endpoint within the “Get Events for a User” section titled in the API documentation.
Test case: success
Start by adding our first test for this endpoint as follows:
-
Create a few variables:
user,eventResponse, and ...