application-resource-attributes.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { getApplicationResourceAttributes } from './application-resource-attributes';
  2. // Mock external dependencies
  3. vi.mock('~/utils/logger', () => ({
  4. default: () => ({
  5. info: vi.fn(),
  6. error: vi.fn(),
  7. }),
  8. }));
  9. // Mock growi-info service
  10. const mockGrowiInfoService = {
  11. getGrowiInfo: vi.fn(),
  12. };
  13. vi.mock('~/server/service/growi-info', () => ({
  14. growiInfoService: mockGrowiInfoService,
  15. }));
  16. describe('getApplicationResourceAttributes', () => {
  17. beforeEach(() => {
  18. vi.clearAllMocks();
  19. });
  20. it('should return complete application resource attributes when growi info is available', async () => {
  21. const mockGrowiInfo = {
  22. type: 'app',
  23. deploymentType: 'standalone',
  24. additionalInfo: {
  25. attachmentType: 'local',
  26. },
  27. };
  28. mockGrowiInfoService.getGrowiInfo.mockResolvedValue(mockGrowiInfo);
  29. const result = await getApplicationResourceAttributes();
  30. expect(result).toEqual({
  31. 'growi.service.type': 'app',
  32. 'growi.deployment.type': 'standalone',
  33. 'growi.attachment.type': 'local',
  34. });
  35. expect(mockGrowiInfoService.getGrowiInfo).toHaveBeenCalledWith({
  36. includeAttachmentInfo: true,
  37. });
  38. });
  39. it('should handle missing additionalInfo gracefully', async () => {
  40. const mockGrowiInfo = {
  41. type: 'app',
  42. deploymentType: 'standalone',
  43. additionalInfo: undefined,
  44. };
  45. mockGrowiInfoService.getGrowiInfo.mockResolvedValue(mockGrowiInfo);
  46. const result = await getApplicationResourceAttributes();
  47. expect(result).toEqual({
  48. 'growi.service.type': 'app',
  49. 'growi.deployment.type': 'standalone',
  50. 'growi.attachment.type': undefined,
  51. });
  52. });
  53. it('should return empty object when growiInfoService throws error', async () => {
  54. mockGrowiInfoService.getGrowiInfo.mockRejectedValue(
  55. new Error('Service unavailable'),
  56. );
  57. const result = await getApplicationResourceAttributes();
  58. expect(result).toEqual({});
  59. });
  60. });