Skip to content

Conversation

scottlovegrove
Copy link
Contributor

@scottlovegrove scottlovegrove commented Sep 12, 2022

Fixes: #133

Fields that weren't being returned in v1 of the REST API may now be returned but have a value of null. Our validation wasn't catering for that. Have updated the partial types to accept the type or NULL.

There were a few other instances of number-based ID usage that hadn't been switched. These have now been corrected.

Testing

You can try and follow the instructions in the readme using the scratch.ts file in order to test this.

import { TodoistApi } from './TodoistApi'

const token = '<TOKEN>'

const api = new TodoistApi(token)

async function doIt() {
    try {
        const projects = await api.getProjects()
        console.log(projects.length)
    } catch (error: unknown) {
        if (error instanceof Error) {
            console.log(error)
        }
        console.log({ error })
    }
}

doIt().catch(() => {
    // noop
})

I found putting breakpoints on the console.logs allowed me to see the problem. Prior to the fix, the ones in the catch would get hit, post-fix, the one inside the try would get hit.

I have updated all the tests to account for all of the partial/nulls though.

@scottlovegrove scottlovegrove self-assigned this Sep 12, 2022
@scottlovegrove scottlovegrove requested review from a team and proxi and removed request for a team September 12, 2022 15:52
@henningmu henningmu requested review from a team and craigcarlyle and removed request for a team September 12, 2022 18:25
Copy link

@craigcarlyle craigcarlyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look reasonable and test plan works as expected 🚀

@scottlovegrove scottlovegrove merged commit 44cac53 into main Sep 13, 2022
@scottlovegrove scottlovegrove deleted the scottl/accept-nulls branch September 13, 2022 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The 2.0.0 version seems broken, every api call returns a ValidationError
2 participants