Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Document not deserializing to the type in model #360

Open
3 tasks done
adilansari opened this issue May 9, 2023 · 0 comments
Open
3 tasks done

[BUG]: Document not deserializing to the type in model #360

adilansari opened this issue May 9, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@adilansari
Copy link
Collaborator

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

@TigrisCollection('shoes')
class Shoe {
    @PrimaryKey({ order: 1 })
    id!: string

    @Field()
    purchaseDate!: string

    @Field({ timestamp: 'createdAt' })
    inserted?: Date
}

For the above collection I expect purchaseDate to be string and inserted to be a Date type in the retrieved document.

Current Behavior

Both inserted and purchaseDate are of Date type.

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

For the following collection

@TigrisCollection('shoes')
class Shoe {
    @PrimaryKey({ order: 1 })
    id!: string

    @Field()
    purchaseDate!: string

    @Field({ timestamp: 'createdAt' })
    inserted?: Date
}
describe('Date field tests', () => {
    let collection: Collection<Shoe>
    beforeEach(async () => {
        const db = getClient(ProjectCatalog).getDatabase()
        collection = await db.createOrUpdateCollection<Shoe>(Shoe)
    })

    it('deserialize date', async () => {
        const docs: Array<Shoe> = [
            {
                id: '1',
                purchaseDate: '2020-04-13T00:00:00.000+08:00',
            },
        ]
        const inserted = await collection.insertMany(docs)
        expect(inserted).toHaveLength(docs.length)

        const readDoc = await collection.findOne()
        expect(readDoc).toBeDefined()
        expect(readDoc?.inserted).toBeInstanceOf(Date) // all good
        
        expect(readDoc?.purchaseDate).not.toBeInstanceOf(Date) // This test fails
        expect(readDoc?.purchaseDate).toBeInstanceOf(String)
    })
})

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

You can find Tigris SDK version on your local dev project by executing npm list | grep "tigrisdata/core"

Failure Logs

Please include any relevant log snippets or files here.

@adilansari adilansari added the bug Something isn't working label May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant