workshop.service.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { beforeEach, describe, expect, it, vi } from 'vitest'
  2. const workshopCall = vi.fn<(method: string, ...args: unknown[]) => Promise<unknown>>()
  3. vi.mock('./steam.service', () => ({
  4. workshopCall: (method: string, ...args: unknown[]) => workshopCall(method, ...args),
  5. getSubscribedItems: async () => []
  6. }))
  7. const { isWallpaperEngineItem } = await import('./workshop.service')
  8. describe('isWallpaperEngineItem', () => {
  9. beforeEach(() => workshopCall.mockReset())
  10. it('accepts an item made for Wallpaper Engine', async () => {
  11. workshopCall.mockResolvedValue({ items: [{ publishedFileId: 5n, consumerAppId: 431960 }] })
  12. expect(await isWallpaperEngineItem('5')).toBe(true)
  13. expect(workshopCall).toHaveBeenCalledWith('getItems', [5n])
  14. })
  15. it('refuses an item of another app and one Steam does not know', async () => {
  16. workshopCall.mockResolvedValue({ items: [{ publishedFileId: 5n, consumerAppId: 730 }] })
  17. expect(await isWallpaperEngineItem('5')).toBe(false)
  18. workshopCall.mockResolvedValue({ items: [null] })
  19. expect(await isWallpaperEngineItem('5')).toBe(false)
  20. })
  21. it('does not guess when Steam reports no app', async () => {
  22. workshopCall.mockResolvedValue({ items: [{ publishedFileId: 5n }] })
  23. expect(await isWallpaperEngineItem('5')).toBe(true)
  24. })
  25. })