diff --git a/README.md b/README.md index ba5d847..cffacd8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ let Habitica = require('habitica'); let api = new Habitica({ uuid: 'your-habitica.com-user-id', token: 'your-habitica.com-api-token', - endpoint: 'custom-url', // defaults to https://habitica.com/api/v2 + endpoint: 'custom-url', // defaults to https://habitica.com/api/v3 }); ``` diff --git a/src/account.js b/src/account.js index 5163674..6a4d52f 100644 --- a/src/account.js +++ b/src/account.js @@ -47,10 +47,10 @@ export default class { confirmPassword: password } - let user = await this._connection.post( - 'register', - {send: creds} - ) + let {data: user} = await this._connection.post( + 'user/auth/local/register', + {send: creds} + ) this._connection.setCredentials({ uuid: user._id, @@ -79,14 +79,14 @@ export default class { username: usernameEmail, password } - let creds = await this._connection.post( - 'user/auth/local', + let {data: creds} = await this._connection.post( + 'user/auth/local/login', {send: loginCreds} ) this._connection.setCredentials({ uuid: creds.id, - token: creds.token + token: creds.apiToken }) return creds diff --git a/src/content.js b/src/content.js index ba1696c..d5582d8 100644 --- a/src/content.js +++ b/src/content.js @@ -36,7 +36,7 @@ export default class { // }) // ``` async get (path) { - let content = await this._connection.get('content') + let {data: content} = await this._connection.get('content') if (path) { let nestedContent = get(content, path) @@ -71,7 +71,7 @@ export default class { // }) // ``` async getKeys (path) { - let content = await this._connection.get('content') + let {data: content} = await this._connection.get('content') if (path) { let nestedContent = get(content, path) @@ -98,7 +98,7 @@ export default class { // }) // ``` async getUserPaths () { - let paths = await this._connection.get('content/paths') + let {data: paths} = await this._connection.get('models/user/paths') return paths } diff --git a/src/index.js b/src/index.js index a738d8e..d4e60c2 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,7 @@ module.exports = class { // // Set up your instance of Habitica. // - // The endpoint will default to https://habitica.com/api/v2 if not provided. + // The endpoint will default to https://habitica.com/api/v3 if not provided. // // ```js // let Habitica = require('habitica') @@ -98,7 +98,7 @@ module.exports = class { // api.setCredentials({ // uuid: 'new-user-id', // token: 'new-api-token', - // endpoint: 'http://localhost:3000/api/v2' + // endpoint: 'http://localhost:3000/api/v3' // }) // ``` setCredentials (creds) { diff --git a/src/lib/connection.js b/src/lib/connection.js index a629876..43251e3 100644 --- a/src/lib/connection.js +++ b/src/lib/connection.js @@ -5,7 +5,7 @@ export default class { constructor (options) { this._uuid = options.uuid this._token = options.token - this._endpoint = options.endpoint || 'https://habitica.com/api/v2' + this._endpoint = options.endpoint || 'https://habitica.com/api/v3' this.delete = this.del } @@ -23,9 +23,15 @@ export default class { } setCredentials (creds = {}) { - this._uuid = creds.uuid || this._uuid - this._token = creds.token || this._token - this._endpoint = creds.endpoint || this._endpoint + if (creds.uuid !== undefined) { + this._uuid = creds.uuid + } + if (creds.token !== undefined) { + this._token = creds.token + } + if (creds.endpoint !== undefined) { + this._endpoint = creds.endpoint + } } get (route, options = {}) { diff --git a/src/tag.js b/src/tag.js index 3becdad..a56e5cc 100644 --- a/src/tag.js +++ b/src/tag.js @@ -31,13 +31,13 @@ export default class { // }) // ``` async get (id) { - let url = 'user/tags' + let url = 'tags' if (id) { url += `/${id}` } - let tags = await this._connection.get(url) + let {data: tags} = await this._connection.get(url) return tags } @@ -55,8 +55,8 @@ export default class { // }) // ``` async post (tagBody) { - let tags = await this._connection.post( - 'user/tags', + let {data: tags} = await this._connection.post( + 'tags', {send: tagBody} ) @@ -80,8 +80,8 @@ export default class { if (!id) throw new IME.MissingArgumentError('Tag id is required') if (!tagBody) throw new IME.MissingArgumentError('Tag body is required') - let tag = await this._connection.put( - `user/tags/${id}`, + let {data: tag} = await this._connection.put( + `tags/${id}`, { send: tagBody } ) @@ -101,7 +101,7 @@ export default class { async del (id) { if (!id) throw new IME.MissingArgumentError('Tag id is required') - let remainingTags = await this._connection.del(`user/tags/${id}`) + let {data: remainingTags} = await this._connection.del(`tags/${id}`) return remainingTags } diff --git a/src/task.js b/src/task.js index 9fda6b8..ee10013 100644 --- a/src/task.js +++ b/src/task.js @@ -1,7 +1,6 @@ // Task // checkmark box // Get em, check em, level up! -import filter from 'lodash/filter' import {INTERNAL_MODULE_ERRORS as IME} from './lib/errors' export default class { @@ -31,13 +30,15 @@ export default class { // }) // ``` async get (id) { - let url = 'user/tasks' + let url = 'tasks' if (id) { url += `/${id}` + } else { + url += '/user' } - let tasks = await this._connection.get(url) + let {data: tasks} = await this._connection.get(url) return tasks } @@ -52,7 +53,7 @@ export default class { // }) // ``` async getDailys () { - return this._filterTasksByType('daily') + return this._filterTasksByType('dailys') } // # task.getRewards() @@ -65,7 +66,7 @@ export default class { // }) // ``` async getRewards () { - return this._filterTasksByType('reward') + return this._filterTasksByType('rewards') } // # task.getHabits() @@ -78,7 +79,7 @@ export default class { // }) // ``` async getHabits () { - return this._filterTasksByType('habit') + return this._filterTasksByType('habits') } // # task.getTodos() @@ -91,7 +92,7 @@ export default class { // }) // ``` async getTodos () { - return this._filterTasksByType('todo') + return this._filterTasksByType('todos') } // # task.score() @@ -146,8 +147,8 @@ export default class { async score (id, direction = 'up', body = {}) { if (!id) throw new IME.MissingArgumentError('Task id is required') - let stats = await this._connection.post( - `user/tasks/${id}/${direction}`, + let {data: stats} = await this._connection.post( + `tasks/${id}/score/${direction}`, { send: body } ) @@ -169,8 +170,8 @@ export default class { // }) // ``` async post (taskBody) { - let task = await this._connection.post( - 'user/tasks', + let {data: task} = await this._connection.post( + 'tasks/user', { send: taskBody } ) return task @@ -193,8 +194,8 @@ export default class { if (!id) throw new IME.MissingArgumentError('Task id is required') if (!taskBody) throw new IME.MissingArgumentError('Task body is required') - let task = await this._connection.put( - `user/tasks/${id}`, + let {data: task} = await this._connection.put( + `tasks/${id}`, { send: taskBody } ) @@ -214,17 +215,16 @@ export default class { async del (id) { if (!id) throw new IME.MissingArgumentError('Task id is required') - let task = await this._connection.del(`user/tasks/${id}`) + let {data: task} = await this._connection.del(`tasks/${id}`) return task } // NOOP async _filterTasksByType (type) { - let tasks = await this._connection.get('user/tasks') - let taskByType = filter(tasks, (task) => { - return task.type === type + let {data: tasks} = await this._connection.get('tasks/user', { + query: {type} }) - return taskByType + return tasks } } diff --git a/src/user.js b/src/user.js index 30d37f3..6684bbd 100644 --- a/src/user.js +++ b/src/user.js @@ -17,7 +17,7 @@ export default class { // }) // ``` async get () { - let user = await this._connection.get('user') + let {data: user} = await this._connection.get('user') return user } @@ -40,7 +40,7 @@ export default class { // }) // ``` async getBuyableGear () { - let gear = await this._connection.get('user/inventory/buy') + let {data: gear} = await this._connection.get('user/inventory/buy') return gear } diff --git a/tasks/start-server.js b/tasks/start-server.js index acc75d2..e8de527 100644 --- a/tasks/start-server.js +++ b/tasks/start-server.js @@ -13,7 +13,7 @@ if (args.length > 2) { process.env.PORT = process.env.HABITICA_PORT || 3321 process.env.NODE_DB_URI = process.env.HABITICA_DB_URI || 'mongodb://localhost/habitica-node-test' -var server = require(`${PATH_TO_HABITICA}/website/src/server.js`) +var server = require(`${PATH_TO_HABITICA}/website/server/`) server.listen(process.env.PORT, function () { if (command) { diff --git a/test/integration/account.test.js b/test/integration/account.test.js index a0d5f19..bb75ce9 100644 --- a/test/integration/account.test.js +++ b/test/integration/account.test.js @@ -8,7 +8,7 @@ describe('Account', () => { beforeEach(() => { api = new Habitica({ - endpoint: `localhost:${process.env.PORT}/api/v2` + endpoint: `localhost:${process.env.PORT}/api/v3` }) username = generateRandomUserName() password = 'password' @@ -94,10 +94,10 @@ describe('Account', () => { beforeEach(async function () { let registerApi = new Habitica({ - endpoint: `localhost:${process.env.PORT}/api/v2` + endpoint: `localhost:${process.env.PORT}/api/v3` }) api = new Habitica({ - endpoint: `localhost:${process.env.PORT}/api/v2` + endpoint: `localhost:${process.env.PORT}/api/v3` }) username = generateRandomUserName() @@ -112,28 +112,28 @@ describe('Account', () => { let creds = await api.account.login(username, password) expect(creds.id).to.exist - expect(creds.token).to.exist + expect(creds.apiToken).to.exist }) it('sets uuid and token after logging in with username', async function () { let creds = await api.account.login(username, password) expect(api.getUuid()).to.be.eql(creds.id) - expect(api.getToken()).to.be.eql(creds.token) + expect(api.getToken()).to.be.eql(creds.apiToken) }) it('logs in with email and password', async function () { let creds = await api.account.login(email, password) expect(creds.id).to.exist - expect(creds.token).to.exist + expect(creds.apiToken).to.exist }) it('sets uuid and token after logging in with email', async function () { let creds = await api.account.login(email, password) expect(api.getUuid()).to.be.eql(creds.id) - expect(api.getToken()).to.be.eql(creds.token) + expect(api.getToken()).to.be.eql(creds.apiToken) }) }) diff --git a/test/integration/content.test.js b/test/integration/content.test.js index e1c211c..1c54c38 100644 --- a/test/integration/content.test.js +++ b/test/integration/content.test.js @@ -3,7 +3,7 @@ import {INTERNAL_MODULE_ERRORS as IME} from '../../src/lib/errors' describe('Content', () => { let api = new Habitica({ - endpoint: `localhost:${process.env.PORT}/api/v2` + endpoint: `localhost:${process.env.PORT}/api/v3` }) describe('#get', () => { diff --git a/test/integration/tag.test.js b/test/integration/tag.test.js index a8c8f6f..f0892be 100644 --- a/test/integration/tag.test.js +++ b/test/integration/tag.test.js @@ -1,22 +1,24 @@ -import _ from 'lodash' +import {v4 as makeUuid} from 'uuid' import {generateUser} from '../support/integration_helper' import Habitica from '../../src/index' import {INTERNAL_MODULE_ERRORS as IME} from '../../src/lib/errors' describe('Tag', () => { let api = new Habitica({ - endpoint: `localhost:${process.env.PORT}/api/v2` + endpoint: `localhost:${process.env.PORT}/api/v3` }) beforeEach(async function () { + this.tag1id = makeUuid() + this.tag2id = makeUuid() let update = { 'tags': [ { - id: 'tag-1', + id: this.tag1id, name: 'tag 1' }, { - id: 'tag-2', + id: this.tag2id, name: 'tag 2' } ] @@ -30,19 +32,19 @@ describe('Tag', () => { expect(tags).to.have.a.lengthOf(2) expect(tags).to.include({ - id: 'tag-1', + id: this.tag1id, name: 'tag 1' }) expect(tags).to.include({ - id: 'tag-2', + id: this.tag2id, name: 'tag 2' }) }) it('gets a specific tag by id', async function () { - let tag = await api.tag.get('tag-1') + let tag = await api.tag.get(this.tag1id) - expect(tag.id).to.eql('tag-1') + expect(tag.id).to.eql(this.tag1id) expect(tag.name).to.eql('tag 1') }) @@ -54,38 +56,26 @@ describe('Tag', () => { describe('#post', () => { it('creates a new tag', async function () { - let tags = await api.tag.post({ + let tag = await api.tag.post({ name: 'new tag' }) - let tag = _.find(tags, {name: 'new tag'}) let fetchedTag = await api.tag.get(tag.id) expect(fetchedTag.id).to.exist + expect(fetchedTag.id).to.eql(tag.id) expect(fetchedTag.name).to.eql('new tag') }) - - it('creates a new tag with specified tag attributes', async function () { - let tags = await api.tag.post({ - name: 'new tag', - id: 'new-tag-id' - }) - - expect(tags).to.include({ - name: 'new tag', - id: 'new-tag-id' - }) - }) }) describe('#put', () => { it('updates an existing tag', async function () { let tag = await api.tag.put( - 'tag-1', + this.tag1id, { name: 'updated tag name' } ) - expect(tag.id).to.eql('tag-1') + expect(tag.id).to.eql(this.tag1id) expect(tag.name).to.eql('updated tag name') }) @@ -99,7 +89,7 @@ describe('Tag', () => { it('throws an error if no tag body is provided', async function () { let err = new IME.MissingArgumentError('Tag body is required') - await expect(api.tag.put('tag-1')) + await expect(api.tag.put(this.tag1id)) .to.eventually.be.rejected.and.eql(err) }) @@ -113,18 +103,12 @@ describe('Tag', () => { describe('#del', () => { it('deletes an existing tag', async function () { - await api.tag.del('tag-1') + await api.tag.del(this.tag1id) - await expect(api.tag.get('tag-1')) + await expect(api.tag.get(this.tag1id)) .to.eventually.be.rejected }) - it('returns the remaining tags', async function () { - let tags = await api.tag.del('tag-1') - - expect(tags).to.eql([{id: 'tag-2', name: 'tag 2'}]) - }) - it('throws an error if no tag id is provided', async function () { let err = new IME.MissingArgumentError('Tag id is required') diff --git a/test/integration/task.test.js b/test/integration/task.test.js index 81efdde..ef76f7a 100644 --- a/test/integration/task.test.js +++ b/test/integration/task.test.js @@ -1,32 +1,41 @@ +import {v4 as makeUuid} from 'uuid' import {generateUser} from '../support/integration_helper' import Habitica from '../../src/index' import {INTERNAL_MODULE_ERRORS as IME} from '../../src/lib/errors' describe('Task', () => { let api = new Habitica({ - endpoint: `localhost:${process.env.PORT}/api/v2` + endpoint: `localhost:${process.env.PORT}/api/v3` }) beforeEach(async function () { - let update = { - 'todos': [ - {type: 'todo', id: 'todo-1'}, - {type: 'todo', id: 'todo-2'} - ], - 'habits': [ - {type: 'habit', id: 'habit-1'}, - {type: 'habit', id: 'habit-2'} - ], - 'dailys': [ - {type: 'daily', id: 'daily-1'}, - {type: 'daily', id: 'daily-2'} - ], - 'rewards': [ - {type: 'reward', id: 'reward-1'}, - {type: 'reward', id: 'reward-2'} - ] - } - await generateUser(update, api) + this.todo1id = makeUuid() + this.todo2id = makeUuid() + this.habit1id = makeUuid() + this.habit2id = makeUuid() + this.daily1id = makeUuid() + this.daily2id = makeUuid() + this.reward1id = makeUuid() + this.reward2id = makeUuid() + + await generateUser(null, api) + + // Remove starting tasks + let tasks = await api.task.get() + + await Promise.all(tasks.map((task) => api.task.del(task._id))) + + // Populate with known tasks + await api.task.post([ + {text: 'task-1', type: 'todo', _id: this.todo1id}, + {text: 'task-2', type: 'todo', _id: this.todo2id}, + {text: 'task-3', type: 'habit', _id: this.habit1id}, + {text: 'task-4', type: 'habit', _id: this.habit2id}, + {text: 'task-5', type: 'daily', _id: this.daily1id}, + {text: 'task-6', type: 'daily', _id: this.daily2id}, + {text: 'task-7', type: 'reward', _id: this.reward1id}, + {text: 'task-8', type: 'reward', _id: this.reward2id} + ]) }) describe('#get', () => { @@ -37,9 +46,10 @@ describe('Task', () => { }) it('gets a specific task by id', async function () { - let task = await api.task.get('todo-1') + let task = await api.task.get(this.todo1id) - expect(task.id).to.eql('todo-1') + expect(task._id).to.eql(this.todo1id) + expect(task.text).to.eql('task-1') }) it('throws error if task does not exist', async function () { @@ -81,7 +91,7 @@ describe('Task', () => { describe('#getTodos', () => { it('gets only todos', async function () { let todos = await api.task.getTodos() - expect(todos).to.have.a.lengthOf(2) + expect(todos).have.a.lengthOf(2) expect(todos[0].type).to.eql('todo') expect(todos[1].type).to.eql('todo') }) @@ -89,65 +99,43 @@ describe('Task', () => { describe('#score', () => { it('scores up a task', async function () { - let { value: originalValue } = await api.task.get('habit-1') - let stats = await api.task.score('habit-1', 'up') - let { value: newValue } = await api.task.get('habit-1') + let { value: originalValue } = await api.task.get(this.habit1id) + let stats = await api.task.score(this.habit1id, 'up') + let { value: newValue } = await api.task.get(this.habit1id) expect(stats.delta).to.be.greaterThan(0) expect(newValue).to.be.greaterThan(originalValue) }) it('scores down a task', async function () { - let { value: originalValue } = await api.task.get('habit-1') - let stats = await api.task.score('habit-1', 'down') - let { value: newValue } = await api.task.get('habit-1') + let { value: originalValue } = await api.task.get(this.habit1id) + let stats = await api.task.score(this.habit1id, 'down') + let { value: newValue } = await api.task.get(this.habit1id) expect(stats.delta).to.be.lessThan(0) expect(newValue).to.be.lessThan(originalValue) }) it('defaults to scoring up', async function () { - let { value: originalValue } = await api.task.get('habit-1') - let stats = await api.task.score('habit-1') - let { value: newValue } = await api.task.get('habit-1') + let { value: originalValue } = await api.task.get(this.habit1id) + let stats = await api.task.score(this.habit1id) + let { value: newValue } = await api.task.get(this.habit1id) expect(stats.delta).to.be.greaterThan(0) expect(newValue).to.be.greaterThan(originalValue) }) - it('creates new habit if it does not already exist', async function () { - await api.task.score('new-habit') - let habit = await api.task.get('new-habit') - - expect(habit.type).to.eql('habit') - }) - - it('allows extra data to be passed in when creating the task', async function () { - let todoBody = { - type: 'todo', - text: 'Custom Name', - notes: 'Custom Note' - } - await api.task.score('new-todo', 'up', todoBody) - - let todo = await api.task.get('new-todo') - - expect(todo.type).to.eql('todo') - expect(todo.text).to.eql('Custom Name') - expect(todo.notes).to.eql('Custom Note') - }) - it('completes task if scored task is a todo', async function () { - await api.task.score('todo-1') - let todo = await api.task.get('todo-1') + await api.task.score(this.todo1id) + let todo = await api.task.get(this.todo1id) expect(todo.completed).to.eql(true) }) it('completes task if scored task is a daily', async function () { - await api.task.score('daily-1') + await api.task.score(this.daily1id) - let daily = await api.task.get('daily-1') + let daily = await api.task.get(this.daily1id) expect(daily.completed).to.eql(true) }) @@ -160,16 +148,18 @@ describe('Task', () => { }) it('thows an error if a non-valid direction is used', async function () { - await expect(api.task.score('habit-1', 'foo')) + await expect(api.task.score(this.habit1id, 'foo')) .to.eventually.be.rejected }) }) describe('#post', () => { it('creates a new task', async function () { - let task = await api.task.post() + let task = await api.task.post({ text: 'foo', type: 'habit' }) - expect(task.id).to.exist + expect(task._id).to.exist + expect(task.text).to.eql('foo') + expect(task.type).to.eql('habit') }) it('creates a new task with specified task attributes', async function () { @@ -188,11 +178,11 @@ describe('Task', () => { describe('#put', () => { it('updates an existing task', async function () { let task = await api.task.put( - 'todo-1', + this.todo1id, { text: 'updated todo name', notes: 'updated todo notes' } ) - expect(task.id).to.eql('todo-1') + expect(task._id).to.eql(this.todo1id) expect(task.text).to.eql('updated todo name') expect(task.notes).to.eql('updated todo notes') }) @@ -207,7 +197,7 @@ describe('Task', () => { it('throws an error if no task body is provided', async function () { let err = new IME.MissingArgumentError('Task body is required') - await expect(api.task.put('habit-1')) + await expect(api.task.put(this.habit1id)) .to.eventually.be.rejected.and.eql(err) }) @@ -221,10 +211,10 @@ describe('Task', () => { describe('#del', () => { it('del an existing task', async function () { - let task = await api.task.del('todo-1') + let task = await api.task.del(this.todo1id) expect(task).to.eql({}) - await expect(api.task.get('todo-1')) + await expect(api.task.get(this.todo1id)) .to.eventually.be.rejected }) diff --git a/test/integration/user.test.js b/test/integration/user.test.js index c40ae9e..5f40fdb 100644 --- a/test/integration/user.test.js +++ b/test/integration/user.test.js @@ -2,7 +2,7 @@ import {generateUser} from '../support/integration_helper' import Habitica from '../../src/index' let api = new Habitica({ - endpoint: `localhost:${process.env.PORT}/api/v2` + endpoint: `localhost:${process.env.PORT}/api/v3` }) describe('User', () => { @@ -15,7 +15,7 @@ describe('User', () => { let user = await api.user.get() expect(user._id).to.eql(api.getUuid()) - expect(user).to.include.keys(['todos', 'habits', 'dailys', 'rewards']) + expect(user).to.include.keys(['tasksOrder', 'tags']) expect(user).to.include.keys(['stats', 'balance', 'preferences', 'flags']) }) }) diff --git a/test/support/integration_helper.js b/test/support/integration_helper.js index 139431c..0b332c7 100644 --- a/test/support/integration_helper.js +++ b/test/support/integration_helper.js @@ -9,7 +9,7 @@ export function generateUser (update = {}, connection) { let email = username + '@example.com' return new Promise((resolve, reject) => { - superagent.post(`localhost:${process.env.PORT}/api/v2/register`) + superagent.post(`localhost:${process.env.PORT}/api/v3/user/auth/local/register`) .accept('application/json') .send({ username, @@ -20,9 +20,9 @@ export function generateUser (update = {}, connection) { .end((err, res) => { if (err) throw new Error(`Error generating user: ${err}`) - let user = res.body + let {data: user} = res.body let userCreds = { - uuid: user._id, + uuid: user.id, token: user.apiToken } @@ -30,7 +30,7 @@ export function generateUser (update = {}, connection) { connection.setCredentials(userCreds) } - updateDocument('users', user._id, update, () => { + updateDocument('users', user.id, update, () => { resolve(userCreds) }) }) diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index 61d8643..de44323 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -12,7 +12,7 @@ describe('Connection', () => { describe('initialization', () => { it('defaults to habitica endpoint', () => { let connection = new Connection(defaultOptions) - expect(connection._endpoint).to.eql('https://habitica.com/api/v2') + expect(connection._endpoint).to.eql('https://habitica.com/api/v3') }) it('accepts an override for endpoint', () => { @@ -63,7 +63,7 @@ describe('Connection', () => { describe('#getEndpoint', () => { it('returns endpoint', () => { let connection = new Connection(defaultOptions) - expect(connection.getEndpoint()).to.eql('https://habitica.com/api/v2') + expect(connection.getEndpoint()).to.eql('https://habitica.com/api/v3') }) }) @@ -103,17 +103,17 @@ describe('Connection', () => { }) it('leaves old endpoint if not passed in after initalization', () => { - expect(connection._endpoint).to.eql('https://habitica.com/api/v2') + expect(connection._endpoint).to.eql('https://habitica.com/api/v3') connection.setCredentials({uuid: 'foo'}) - expect(connection._endpoint).to.eql('https://habitica.com/api/v2') + expect(connection._endpoint).to.eql('https://habitica.com/api/v3') }) it('sets endpoint after iniitalization', () => { - expect(connection._endpoint).to.eql('https://habitica.com/api/v2') + expect(connection._endpoint).to.eql('https://habitica.com/api/v3') - connection.setCredentials({endpoint: 'http://localhost:3321/api/v2'}) - expect(connection._endpoint).to.eql('http://localhost:3321/api/v2') + connection.setCredentials({endpoint: 'http://localhost:3321/api/v3'}) + expect(connection._endpoint).to.eql('http://localhost:3321/api/v3') }) }) @@ -122,7 +122,7 @@ describe('Connection', () => { beforeEach(() => { connection = new Connection(defaultOptions) - habiticaUrl = nock('https://habitica.com/api/v2').get('/user') + habiticaUrl = nock('https://habitica.com/api/v3').get('/user') }) it('returns a promise', () => { @@ -132,7 +132,7 @@ describe('Connection', () => { }) it('takes in an optional query parameter', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .get('/group') .query({type: 'party'}) .reply(200) @@ -143,7 +143,7 @@ describe('Connection', () => { }) it('ignores send parameter if passed in', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .get('/group') .reply(200) @@ -199,7 +199,7 @@ describe('Connection', () => { describe('#post', () => { beforeEach(() => { - habiticaUrl = nock('https://habitica.com/api/v2') + habiticaUrl = nock('https://habitica.com/api/v3') .post('/user/tasks') }) @@ -214,7 +214,7 @@ describe('Connection', () => { }) it('takes in an optional query parameter', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .post('/user/tasks') .query({ type: 'habit', @@ -234,7 +234,7 @@ describe('Connection', () => { }) it('takes in an optional send parameter', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .post('/group', { type: 'party' }) @@ -276,7 +276,7 @@ describe('Connection', () => { describe('#put', () => { beforeEach(() => { - habiticaUrl = nock('https://habitica.com/api/v2') + habiticaUrl = nock('https://habitica.com/api/v3') .put('/user/tasks') }) @@ -291,7 +291,7 @@ describe('Connection', () => { }) it('takes in an optional query parameter', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .put('/user/tasks') .query({ type: 'habit', @@ -311,7 +311,7 @@ describe('Connection', () => { }) it('takes in an optional send parameter', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .put('/group', { type: 'party' }) @@ -353,7 +353,7 @@ describe('Connection', () => { describe('#del', () => { beforeEach(() => { - habiticaUrl = nock('https://habitica.com/api/v2') + habiticaUrl = nock('https://habitica.com/api/v3') .delete('/user/tasks') }) @@ -368,7 +368,7 @@ describe('Connection', () => { }) it('takes in an optional query parameter', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .delete('/user/tasks') .query({ type: 'habit', @@ -388,7 +388,7 @@ describe('Connection', () => { }) it('takes in an optional send parameter', async function () { - let expectedRequest = nock('https://habitica.com/api/v2') + let expectedRequest = nock('https://habitica.com/api/v3') .delete('/group', { type: 'party' }) diff --git a/test/unit/habitica.test.js b/test/unit/habitica.test.js index 393ba47..41a63df 100644 --- a/test/unit/habitica.test.js +++ b/test/unit/habitica.test.js @@ -20,7 +20,7 @@ describe('Habitica Api', () => { describe('#getEndpoint', () => { it('returns token', () => { - expect(api.getEndpoint()).to.eql('https://habitica.com/api/v2') + expect(api.getEndpoint()).to.eql('https://habitica.com/api/v3') }) })