import {expect} from "chai"
import {Server} from "../../../../source/data/datasource/server.mjs";


describe('Server', function () {

    it('should transform data', function () {

        let writeCallbackCalled = false
        let readCallbackCalled = false

        const server = new Server({
            write: {
                mapping: {
                    transformer: "call:onWrite",
                    callbacks: {
                        onWrite: (data) => {
                            writeCallbackCalled = true
                            return data
                        }
                    }
                },
                sheathing: {
                    object: {
                        demo: 1,
                        data: {
                            xyz: undefined
                        }
                    },
                    path: "data.xyz",
                },
            },
            read: {
                mapping: {
                    transformer: "call:onRead",
                    callbacks: {
                        onRead: (data) => {
                            readCallbackCalled = true
                            return data
                        }
                    }
                },
                path: 'data.xyz',
            }
        })

        expect(server.transformServerPayload({demo: 1, data: {xyz: 2}})).to.deep.equal({demo: 1, data: {xyz: 2}})
        expect(server.prepareServerPayload({demo: 1, data: {xyz: 2}})).to.deep.equal({demo: 1, data: {xyz: 2}})


    })

});
