Skip to content

Commit

Permalink
test(TogglApi): test user info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesantana committed Dec 18, 2023
1 parent 3ea9172 commit 58f7996
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/infrastructure/data-sources/toggl.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';

chai.use(chaiAsPromised);
const {expect} = chai;

import {http} from "../../../dist/infrastructure/data-sources"; // dist directory is not an error. Is due to how commands are tested based on transpiled code.
import {TogglApi} from "../../../src/infrastructure/data-sources";
import {AuthorizationError, NotFoundError, RequestError, ServerError} from "../../../src/infrastructure/errors";
import {buildTogglProject, buildTogglTimeEntry} from "../../builders";
import httpMock from "../../http.mock";

chai.use(chaiAsPromised);
const {expect} = chai;

describe('Toggl API should', () => {
const workspaceId = 42;
const api = new TogglApi({http, token: 'irrelevant-token', workspaceId})
Expand All @@ -20,6 +20,17 @@ describe('Toggl API should', () => {
httpMock.reset()
})

it('get user info', async () => {
const data = {a: 42, b: 'meh'}
httpMock
.onGet(`${TogglApi.baseUrl}/api/v9/me?with_related_data=true`)
.reply(200, data)

const result = await TogglApi.getUserInfo('irrelevant', http)

expect(result).to.deep.equal(data)
})

describe('create time entry', () => {
it('successfully', async () => {
const start = new Date()
Expand Down Expand Up @@ -201,6 +212,7 @@ describe('Toggl API should', () => {

expect(result).to.deep.equal(entries)
})

it('with from date', async () => {
const from = new Date('2023-05-15')
const to = new Date()
Expand Down Expand Up @@ -262,7 +274,7 @@ describe('Toggl API should', () => {
})

describe('update time entry', () => {
const entry = buildTogglTimeEntry()
const entry = buildTogglTimeEntry()
it('successfully', async () => {
httpMock
.onPut(`${TogglApi.baseUrl}/api/v9/workspaces/${workspaceId}/time_entries/${entry.id}`)
Expand Down

0 comments on commit 58f7996

Please sign in to comment.