Repository: facebook/docusaurus
File: packages/docusaurus-plugin-content-blog/src/__tests__/authorsMap.test.ts (TypeScript)

Code before:
    ).resolves.toBeDefined();
  });

  it('getAuthorsMap can read json file', async () => {
    await expect(
      getAuthorsMap({
        contentPaths,
        authorsMapPath: 'authors.json',
        authorsBaseRoutePath: '/authors',
        baseUrl: '/',
      }),
    ).resolves.toBeDefined();
  });

  it('getAuthorsMap can return undefined if yaml file not found', async () => {
    await expect(
      getAuthorsMap({
        contentPaths,
        authorsMapPath: 'authors_does_not_exist.yml',
        authorsBaseRoutePath: '/authors',
        baseUrl: '/',
      }),
    ).resolves.toBeUndefined();
  });

  it('getAuthorsMap can return img with relative path if baseUrl is set', async () => {
    const authorsMap = await getAuthorsMap({
      contentPaths,
      authorsMapPath: 'authors.yml',
      authorsBaseRoutePath: '/authors',
      baseUrl: '/baseUrl',
    });
    expect(authorsMap).toBeDefined();
    expect(authorsMap?.ozaki?.imageURL).toBe('/baseUrl/img/ozaki.jpg');
  });
});

describe('validateAuthorsMapInput', () => {
  it('accept valid authors map', () => {
    const authorsMap: AuthorsMapInput = {
      slorber: {
        name: 'Sébastien Lorber',
        title: 'maintainer',
        url: 'https://sebastienlorber.com',
        imageURL: 'https://github.com/slorber.png',
        key: 'slorber',
        page: false,
      },
      yangshun: {
        name: 'Yangshun Tay',
        imageURL: 'https://github.com/yangshun.png',

Review comment (bug):
This baseUrl is applied in 2 separate places. We need more tests, including `getBlogPostAuthors`, not just for the authors map.

I also need to see that tests cover one important edge case: that you don't reapply the baseUrl on `getBlogPostAuthors` if the author comes from the author map (since it was already applied the baseUrl). We don't want to have `/baseUrl/baseUrl/img/xyz.png` (unless the user puts an image in `static/baseUrl/img/xyz.png` which is unlikely)



Code after:
    ).resolves.toBeDefined();
  });

  it('getAuthorsMap can read json file', async () => {
    await expect(
      getAuthorsMap({
        contentPaths,
        authorsMapPath: 'authors.json',
        authorsBaseRoutePath: '/authors',
        baseUrl: '/',
      }),
    ).resolves.toBeDefined();
  });

  it('getAuthorsMap can return undefined if yaml file not found', async () => {
    await expect(
      getAuthorsMap({
        contentPaths,
        authorsMapPath: 'authors_does_not_exist.yml',
        authorsBaseRoutePath: '/authors',
        baseUrl: '/',
      }),
    ).resolves.toBeUndefined();
  });

  it('getAuthorsMap return imageURL with relative path', async () => {
    const authorsMap = await getAuthorsMap({
      contentPaths,
      authorsMapPath: 'authors.yml',
      authorsBaseRoutePath: '/authors',
      baseUrl: '/',
    });
    expect(authorsMap?.ozaki?.imageURL).toBe('/ozaki.png');
  });

  it('getAuthorsMap normalize imageURL with baseUrl', async () => {
    const authorsMap = await getAuthorsMap({
      contentPaths,
      authorsMapPath: 'authors.yml',
      authorsBaseRoutePath: '/authors',
      baseUrl: '/baseUrl/',
    });
    expect(authorsMap?.ozaki?.imageURL).toBe('/baseUrl/ozaki.png');
  });

  it('getAuthorsMap return imageURL with relative subdir path', async () => {
    const authorsMap = await getAuthorsMap({
      contentPaths,
      authorsMapPath: 'authors.yml',
      authorsBaseRoutePath: '/authors',
      baseUrl: '/',