forked from triggerdotdev/trigger.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_get_api-v1-timezones.ts
1 lines (1 loc) · 2.81 KB
/
test_get_api-v1-timezones.ts
1
import axios from 'axios';\n\ndescribe('GET /api/v1/timezones', () => {\n const baseURL = process.env.API_BASE_URL || '';\n const authToken = process.env.API_AUTH_TOKEN || '';\n let axiosInstance;\n\n beforeAll(() => {\n axiosInstance = axios.create({\n baseURL,\n validateStatus: () => true, // allow non-2xx responses so we can test error conditions\n headers: {\n // Use template literals for authorization header\n Authorization: `Bearer ${authToken}`\n }\n });\n });\n\n it('should return 200 and valid JSON when excludeUtc is not provided', async () => {\n const response = await axiosInstance.get('/api/v1/timezones');\n expect(response.status).toBe(200);\n // Response Headers Validation\n expect(response.headers['content-type']).toContain('application/json');\n // Response Body Validation\n expect(response.data).toBeDefined();\n // Assuming the response schema includes an array property named timezones\n expect(Array.isArray(response.data.timezones)).toBe(true);\n });\n\n it('should return 200 with excludeUtc=true', async () => {\n const response = await axiosInstance.get('/api/v1/timezones?excludeUtc=true');\n expect(response.status).toBe(200);\n expect(response.headers['content-type']).toContain('application/json');\n expect(Array.isArray(response.data.timezones)).toBe(true);\n // Additional checks to confirm UTC is excluded if needed.\n });\n\n it('should return 200 with excludeUtc=false', async () => {\n const response = await axiosInstance.get('/api/v1/timezones?excludeUtc=false');\n expect(response.status).toBe(200);\n expect(response.headers['content-type']).toContain('application/json');\n expect(Array.isArray(response.data.timezones)).toBe(true);\n // Additional checks to confirm UTC is included if needed.\n });\n\n it('should return 400 or 422 if excludeUtc is invalid type', async () => {\n // Providing an invalid string in place of a boolean should yield 400 or 422.\n const response = await axiosInstance.get('/api/v1/timezones?excludeUtc=abc');\n expect([400, 422]).toContain(response.status);\n });\n\n it('should return 401 or 403 if no auth token is provided', async () => {\n const noAuthInstance = axios.create({\n baseURL,\n validateStatus: () => true\n });\n const response = await noAuthInstance.get('/api/v1/timezones');\n expect([401, 403]).toContain(response.status);\n });\n\n it('should return 401 or 403 if invalid auth token is provided', async () => {\n const invalidAuthInstance = axios.create({\n baseURL,\n validateStatus: () => true,\n headers: {\n Authorization: 'Bearer invalidTokenHere'\n }\n });\n const response = await invalidAuthInstance.get('/api/v1/timezones');\n expect([401, 403]).toContain(response.status);\n });\n});\n