Fetch live schools from db then generate and execute test cases for each school.
I have tried with beforeAll hook data fetched perfectly but was not able to generate dynamic test cases.
let token = ''
let liveSchools: any[] = []
const seconds = 1000
describe('GB Live Establishment API Tests', () => {
beforeAll(async () => {
const response = await server.post('/v1/login').send(credentials)
token = response.body.data.access_token
// Fetch live schools
liveSchools = await fetchLiveSchools()
})
// Step 2: Test to ensure live schools are fetched successfully
it('should fetch live schools', () => {
expect(liveSchools.length).toBeGreaterThan(0)
})
liveSchools.forEach((school, index) => {
it(
`should return basic details of establishment ${school.slug} (row ${index + 1})`,
async () => {
const result = await server
.get(`/v1/establishment/${school.slug}`)
.auth(token, { type: 'bearer' })
// Assertions for the dynamic test
expect(result.body.data.slug).toBe(school.slug)
expect(result.statusCode).toBe(200)
}
)
})
})