Skip to content

Commit

Permalink
test: fix tests for jest 27 support
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jun 3, 2021
1 parent 3e7190d commit d1a428e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 54 deletions.
18 changes: 6 additions & 12 deletions src/app.test.js
@@ -1,30 +1,27 @@
import app from './app.js'

describe('app', () => {
test('get a single application', async (done) => {
test('get a single application', async () => {
try {
const application = await app({ id: 284882215, include_ratings: false })
expect(application.id).toEqual(284882215)
expect(application.title).toEqual('Facebook')
done()
} catch (error) {
expect(error).toBeUndefined()
done(error)
}
})

test('should throw error on not found', async (done) => {
test('should throw error on not found', async () => {
try {
await app({ id: '123456789' })
done(new Error(`Invalid`))
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
expect(error.message).toEqual('Application not found')
done()
}
})

test('should include ratings', async (done) => {
test('should include ratings', async () => {
try {
const application = await app({ id: 284882215, include_ratings: true })
expect(application.id).toEqual(284882215)
Expand All @@ -33,20 +30,17 @@ describe('app', () => {
expect(application.reviews).toBeTruthy()
expect(application.histogram).toBeDefined()
expect(application.ratings).toBeDefined()
done()
} catch (error) {
expect(error).toBeUndefined()
done(error)
}
})

test('should set request options', async (done) => {
test('should set request options', async () => {
try {
await app({ id: 284882215 }, { method: 'DELETE' })
done(new Error(`Invalid`))
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
done()
}
})
})
19 changes: 7 additions & 12 deletions src/developer.test.js
@@ -1,48 +1,43 @@
import developer from './developer.js'

describe('developer', () => {
test('get developer', async (done) => {
test('get developer', async () => {
try {
const { account, applications } = await developer({ id: 284882218 })
expect(account).toBeDefined()
expect(applications).toBeInstanceOf(Array)
expect(applications.length > 0).toBeTruthy()
} catch (error) {
expect(error).toBeUndefined()
} finally {
done()
}
})

test('should throw error on invalid id', async (done) => {
test('should throw error on invalid id', async () => {
try {
await developer({ id: null })
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
expect(error.message).toEqual('Id is required')
} finally {
done()
}
})

test('should throw error on invalid country', async (done) => {
test('should throw error on invalid country', async () => {
try {
await developer({ id: 284882215, country: 'HELLO' })
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
expect(error.message).toEqual('Invalid country id')
} finally {
done()
}
})

test('should set request options', async (done) => {
test('should set request options', async () => {
try {
await developer({ id: 284882215 }, { method: 'DELETE' })
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
} finally {
done()
}
})
})
10 changes: 4 additions & 6 deletions src/ratings.test.js
@@ -1,26 +1,24 @@
import ratings from './ratings.js'

describe('ratings', () => {
it('should get ratings properly', async (done) => {
it('should get ratings properly', async () => {
try {
const r = await ratings({ id: 284882215, country: 'US' })
expect(r.ratings).toBeDefined()
expect(r.histogram).toBeInstanceOf(Object)
expect(Object.keys(r.histogram).length).toEqual(5)
} catch (error) {
expect(error).toBeUndefined()
} finally {
done()
}
})

test('should set request options', async (done) => {
test('should set request options', async () => {
try {
await ratings({ id: 284882215, country: 'us' }, { method: 'DELETE' })
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
} finally {
done()
expect(error.message.includes('Invalid')).toBeFalsy()
}
})
})
23 changes: 8 additions & 15 deletions src/reviews.test.js
@@ -1,7 +1,7 @@
import reviews from './reviews.js'

describe('reviews', () => {
test('should return proper reviews list', async (done) => {
test('should return proper reviews list', async () => {
try {
const results = await reviews({ id: 284882215, country: 'us', page: 1 })
expect(results).toBeInstanceOf(Array)
Expand All @@ -18,56 +18,49 @@ describe('reviews', () => {
})
} catch (error) {
expect(error).toBeUndefined()
} finally {
done()
}
})

test('should throw error on missing id', async (done) => {
test('should throw error on missing id', async () => {
try {
await reviews({})
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
expect(error.message).toEqual('Id should be defined')
} finally {
done()
}
})

test('should throw error on invalid sort field', async (done) => {
test('should throw error on invalid sort field', async () => {
try {
await reviews({ id: 284882215, sort_by: 'hello-world' })
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
expect(error.message).toEqual(
'Invalid sort field. Proper fields are mostRecent, mostHelpful.',
)
} finally {
done()
}
})

test('should throw error on invalid page', async (done) => {
test('should throw error on invalid page', async () => {
try {
await reviews({ id: 284882215, page: 100 })
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
expect(error.message).toEqual('Page should be between 1 and 10.')
} finally {
done()
}
})

test('should set request options', async (done) => {
test('should set request options', async () => {
try {
await reviews(
{ id: 284882215, country: 'us', page: 1 },
{ method: 'DELETE' },
)
} catch (error) {
expect(error).toBeDefined()
} finally {
done()
}
})
})
15 changes: 6 additions & 9 deletions src/search.test.js
@@ -1,40 +1,37 @@
import search from './search.js'

describe('search', () => {
test('search an application', async (done) => {
test('search an application', async () => {
try {
const results = await search({ term: 'facebook' })
expect(results).toBeInstanceOf(Array)
expect(results[0].appId).toEqual('com.facebook.Facebook')
done()
} catch (error) {
expect(error).toBeUndefined()
done(error)
}
})

test('should throw an error on invalid country', async (done) => {
test('should throw an error on invalid country', async () => {
try {
const results = await search({
term: 'facebook',
country: 'laba daba lup lup',
})
expect(results).toBeUndefined()
done(new Error(`Country should have throwed an error`))
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
expect(error.message).toEqual('Invalid country id')
done()
}
})

test('should set request options', async (done) => {
test('should set request options', async () => {
try {
await search({ term: 'facebook' }, { method: 'DELETE' })
done(new Error(`Invalid`))
throw new Error(`Invalid`)
} catch (error) {
expect(error).toBeDefined()
done()
expect(error.message.includes('Invalid')).toBeFalsy()
}
})
})

0 comments on commit d1a428e

Please sign in to comment.