diff --git a/__mocks__/@vtex/diagnostics-semconv.test.ts b/__mocks__/@vtex/diagnostics-semconv.test.ts new file mode 100644 index 000000000..fd5ffef74 --- /dev/null +++ b/__mocks__/@vtex/diagnostics-semconv.test.ts @@ -0,0 +1,160 @@ +import { + ATTR_VTEX_ACCOUNT_NAME, + ATTR_VTEX_IO_WORKSPACE_NAME, + ATTR_VTEX_IO_WORKSPACE_TYPE, + ATTR_VTEX_IO_APP_ID, + ATTR_VTEX_IO_APP_AUTHOR_TYPE, + ATTR_VTEX_IO_CLUSTER_ID, + ATTR_VTEX_IO_CLUSTER_ROLE, +} from './diagnostics-semconv' + +describe('@vtex/diagnostics-semconv mock', () => { + describe('exported constants', () => { + it('should export ATTR_VTEX_ACCOUNT_NAME with correct value', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_ACCOUNT_NAME).toBe('vtex.account.name') + }) + + it('should export ATTR_VTEX_IO_WORKSPACE_NAME with correct value', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_IO_WORKSPACE_NAME).toBe('vtex_io.workspace.name') + }) + + it('should export ATTR_VTEX_IO_WORKSPACE_TYPE with correct value', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_IO_WORKSPACE_TYPE).toBe('vtex_io.workspace.type') + }) + + it('should export ATTR_VTEX_IO_APP_ID with correct value', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_IO_APP_ID).toBe('vtex_io.app.id') + }) + + it('should export ATTR_VTEX_IO_APP_AUTHOR_TYPE with correct value', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_IO_APP_AUTHOR_TYPE).toBe('vtex_io.app.author-type') + }) + + it('should export ATTR_VTEX_IO_CLUSTER_ID with correct value', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_IO_CLUSTER_ID).toBe('vtex_io.cluster.id') + }) + + it('should export ATTR_VTEX_IO_CLUSTER_ROLE with correct value', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_IO_CLUSTER_ROLE).toBe('vtex_io.cluster.role') + }) + }) + + describe('constant types', () => { + it('should have all constants as strings', () => { + // Arrange & Act & Assert + expect(typeof ATTR_VTEX_ACCOUNT_NAME).toBe('string') + expect(typeof ATTR_VTEX_IO_WORKSPACE_NAME).toBe('string') + expect(typeof ATTR_VTEX_IO_WORKSPACE_TYPE).toBe('string') + expect(typeof ATTR_VTEX_IO_APP_ID).toBe('string') + expect(typeof ATTR_VTEX_IO_APP_AUTHOR_TYPE).toBe('string') + expect(typeof ATTR_VTEX_IO_CLUSTER_ID).toBe('string') + expect(typeof ATTR_VTEX_IO_CLUSTER_ROLE).toBe('string') + }) + }) + + describe('constant immutability', () => { + it('should not allow reassignment of ATTR_VTEX_ACCOUNT_NAME', () => { + // Arrange & Act & Assert + expect(() => { + ;(ATTR_VTEX_ACCOUNT_NAME as any) = 'new-value' + }).not.toThrow() + expect(ATTR_VTEX_ACCOUNT_NAME).toBe('vtex.account.name') + }) + + it('should not allow reassignment of ATTR_VTEX_IO_WORKSPACE_NAME', () => { + // Arrange & Act & Assert + expect(() => { + ;(ATTR_VTEX_IO_WORKSPACE_NAME as any) = 'new-value' + }).not.toThrow() + expect(ATTR_VTEX_IO_WORKSPACE_NAME).toBe('vtex_io.workspace.name') + }) + }) + + describe('constant naming conventions', () => { + it('should follow consistent naming pattern for VTEX attributes', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_ACCOUNT_NAME).toMatch(/^vtex\./) + }) + + it('should follow consistent naming pattern for VTEX IO attributes', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_IO_WORKSPACE_NAME).toMatch(/^vtex_io\./) + expect(ATTR_VTEX_IO_WORKSPACE_TYPE).toMatch(/^vtex_io\./) + expect(ATTR_VTEX_IO_APP_ID).toMatch(/^vtex_io\./) + expect(ATTR_VTEX_IO_APP_AUTHOR_TYPE).toMatch(/^vtex_io\./) + expect(ATTR_VTEX_IO_CLUSTER_ID).toMatch(/^vtex_io\./) + expect(ATTR_VTEX_IO_CLUSTER_ROLE).toMatch(/^vtex_io\./) + }) + + it('should contain appropriate domain separators', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_ACCOUNT_NAME).toContain('.') + expect(ATTR_VTEX_IO_WORKSPACE_NAME).toContain('.') + expect(ATTR_VTEX_IO_WORKSPACE_TYPE).toContain('.') + expect(ATTR_VTEX_IO_APP_ID).toContain('.') + expect(ATTR_VTEX_IO_APP_AUTHOR_TYPE).toContain('.') + expect(ATTR_VTEX_IO_CLUSTER_ID).toContain('.') + expect(ATTR_VTEX_IO_CLUSTER_ROLE).toContain('.') + }) + }) + + describe('constant uniqueness', () => { + it('should have unique values for all constants', () => { + // Arrange + const constants = [ + ATTR_VTEX_ACCOUNT_NAME, + ATTR_VTEX_IO_WORKSPACE_NAME, + ATTR_VTEX_IO_WORKSPACE_TYPE, + ATTR_VTEX_IO_APP_ID, + ATTR_VTEX_IO_APP_AUTHOR_TYPE, + ATTR_VTEX_IO_CLUSTER_ID, + ATTR_VTEX_IO_CLUSTER_ROLE, + ] + + // Act + const uniqueConstants = new Set(constants) + + // Assert + expect(uniqueConstants.size).toBe(constants.length) + }) + }) + + describe('constant non-emptiness', () => { + it('should not have empty string values', () => { + // Arrange & Act & Assert + expect(ATTR_VTEX_ACCOUNT_NAME.length).toBeGreaterThan(0) + expect(ATTR_VTEX_IO_WORKSPACE_NAME.length).toBeGreaterThan(0) + expect(ATTR_VTEX_IO_WORKSPACE_TYPE.length).toBeGreaterThan(0) + expect(ATTR_VTEX_IO_APP_ID.length).toBeGreaterThan(0) + expect(ATTR_VTEX_IO_APP_AUTHOR_TYPE.length).toBeGreaterThan(0) + expect(ATTR_VTEX_IO_CLUSTER_ID.length).toBeGreaterThan(0) + expect(ATTR_VTEX_IO_CLUSTER_ROLE.length).toBeGreaterThan(0) + }) + }) + + describe('re-export consistency', () => { + it('should export all seven constants', async () => { + // Arrange + const module = await import('./diagnostics-semconv') + + // Act + const exportedKeys = Object.keys(module) + + // Assert + expect(exportedKeys).toContain('ATTR_VTEX_ACCOUNT_NAME') + expect(exportedKeys).toContain('ATTR_VTEX_IO_WORKSPACE_NAME') + expect(exportedKeys).toContain('ATTR_VTEX_IO_WORKSPACE_TYPE') + expect(exportedKeys).toContain('ATTR_VTEX_IO_APP_ID') + expect(exportedKeys).toContain('ATTR_VTEX_IO_APP_AUTHOR_TYPE') + expect(exportedKeys).toContain('ATTR_VTEX_IO_CLUSTER_ID') + expect(exportedKeys).toContain('ATTR_VTEX_IO_CLUSTER_ROLE') + }) + }) +})