aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/__tests__/tryUrls.test.ts
blob: ebc2f6bdc3d31d8ff1caaadab858abb42bbc7862 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import fileExists from '../fileExists'
import tryUrls from '../tryUrls';
import transparentPng from '../../constants/transparentPng'
jest.mock('../fileExists')

const mockFileExists = fileExists as jest.MockedFunction<typeof fileExists>;

describe('tryUrls', () => {
    it('Should try multiple file extensions', async () => {
        const url = "localhost/stoneddiscord/assets"
        mockFileExists
            .mockReturnValueOnce(Promise.resolve(false))
            .mockReturnValueOnce(Promise.resolve(false))
            .mockReturnValueOnce(Promise.resolve(false))
            .mockReturnValueOnce(Promise.resolve(true))
        const actual = await tryUrls(url)
        const expected = 'localhost/stoneddiscord/assets.apng'
        expect(actual).toBe(expected);
    });

    it('Should return a transparent png if it cant find any assets', async () => {
        const url = "localhost/stoneddiscord/assets"
        mockFileExists
            .mockReturnValue(Promise.resolve(false))
        const actual = await tryUrls(url)
        const expected = transparentPng
        expect(actual).toBe(expected);
    });
})