text: import { labeledLogger } from '../../../lib/labeled-logger.js';
  
  import { fetchUserById } from '../../../lib/fetch-user-by-id/index.js';
  
  const { log } = labeledLogger();
  
  // --- declare function ---
  
  /**
   *A function that fetches a user and returns name and email address
   * @param {number} user ID - the user ID to fetch
   * @returns {promis <String>} A prmise that resolves user name and email
   *  @throws {error} {status number}: {status text}
   */
  const usernameAndEmail = (id = 0) => {
    return fetchUserById(id)
    .then((res)=> {
      if(!res.ok) {
        throw new Error(`${res.status}. ${res.statusText}`)
      }
      return res.json();
    })
    .then((user) => {
      return `${user.id}. ${user.username}, ${user.email} `
    });
  
  };
  
  // --- test function ---
  
  describe("usernameAndEmail: returns a user's name", () => {
    it("gets user 2's name", () => {
      return usernameAndEmail(2).then((actual) => {
        expect(actual).toEqual('2. Antonette, Shanna@melissa.tv');
      });
    });
    it("gets user 3's name", () => {
      return usernameAndEmail(4).then((actual) => {
        expect(actual).toEqual('4. Karianne, Julianne.OConner@kory.org');
      });
    });
    it("gets user 4's name", () => {
      return usernameAndEmail(7).then((actual) => {
        expect(actual).toEqual('7. Elwyn.Skiles, Telly.Hoeger@billy.biz');
      });
    });
    it("gets user 8's name", () => {
      return usernameAndEmail(10).then((actual) => {
        expect(actual).toEqual('10. Moriah.Stanton, Rey.Padberg@karina.biz');
      });
    });
  });
  
  log('= = = =  the call stack is empty  = = = =');
  