Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('does not convert resource requests if resourceCase option is \'none\'', () => {
expect.assertions(3)
const api = new Kitsu({
resourceCase: 'none'
})
expect(api.resCase('long-word')).toBe('long-word')
expect(api.resCase('long_word')).toBe('long_word')
expect(api.resCase('longWord')).toBe('longWord')
})
it('uses Kitsu.io\'s API by default', () => {
expect.assertions(1)
const api = new Kitsu()
expect(api.axios.defaults.baseURL).toBe('https://kitsu.io/api/edge')
})
it('sets additional headers', () => {
expect.assertions(1)
const api = new Kitsu()
api.headers.Key = 'value'
expect(api.headers.Key).toBe('value')
})
describe('method aliases', () => {
const api = new Kitsu()
it('aliases fetch to get', () => {
expect.assertions(1)
expect(api.fetch).toEqual(api.get)
})
it('aliases update to patch', () => {
expect.assertions(1)
expect(api.update).toEqual(api.patch)
})
it('aliases create to post', () => {
expect.assertions(1)
expect(api.create).toEqual(api.post)
})
it('should return false if Authorization header not set', () => {
expect.assertions(1)
const api = new Kitsu()
expect(api.isAuth).toBe(false)
})
it('does not convert types into camelCase if camelCaseTypes option is false', () => {
expect.assertions(3)
const api = new Kitsu({
camelCaseTypes: false
})
expect(api.camel('long-word')).toBe('long-word')
expect(api.camel('long_word')).toBe('long_word')
expect(api.camel('longWord')).toBe('longWord')
})
it('should throw an error if not logged in', async () => {
expect.assertions(1)
try {
const kitsu = new Kitsu()
await kitsu.whoAmI()
} catch (e) {
expect(e.message).toEqual('Not authenticated')
}
})
})
it('should return true if Authorization header is set by method', () => {
expect.assertions(1)
const api = new Kitsu()
api.headers['Authorization'] = 'value'
expect(api.isAuth).toBe(true)
})
})
it('sends headers', async done => {
expect.assertions(1)
const api = new Kitsu({ headers: { Authorization: true } })
mock.onPost('/anime').reply(config => {
expect(config.headers).toEqual({
Accept: 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json',
Authorization: true,
extra: true
})
return [ 200 ]
})
api.post('anime', { id: '1', type: 'anime' }, { extra: true }).catch(err => {
done.fail(err)
})
done()
})
it('uses pluralize by default', () => {
expect.assertions(2)
const api = new Kitsu()
expect(api.plural).toEqual(pluralize)
expect(api.plural('apple')).toBe('apples')
})