UNPKG

firebase-dates-util

Version:

A util package to transform dates string, numbers or Date Objects to firebase Timestamp and viceversa

346 lines (345 loc) 11.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEEP_OBJECT = exports.OBJ_OBJECTS = exports.OBJ_ARRAYS = exports.SIMPLE_OBJ = void 0; const firestore_1 = require("firebase/firestore"); const timestampDate = firestore_1.Timestamp.fromDate(new Date()); exports.SIMPLE_OBJ = { obj: { nombre: 'Prueba ', date: new Date(), createdAt: 12312324432, startAt: '2022-06-12', format: new Date(), }, expecting: (TIPO) => { return { nombre: expect.any(String), date: expect.any(TIPO), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), format: expect.any(TIPO), }; }, }; exports.OBJ_ARRAYS = { obj: { name: 'Pedro', date: new Date(), fieldDate: '2022-06-12', birth: timestampDate, createdAt: null, posts: [ { id: 1, updatedAt: undefined, createdBy: 'Jow Dea', createdAt: new Date(), startAt: 23423523423, finishAt: '2022-06-12', }, ], memebers: ['234233', 34234, new Date()], }, expecting: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: expect.any(TIPO), birth: expect.any(TIPO), createdAt: null, posts: [ { id: expect.any(Number), updatedAt: undefined, createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, ], memebers: [expect.any(String), expect.any(Number), expect.any(Date)], }; }, }; exports.OBJ_OBJECTS = { obj: { name: 'Pedro', date: new Date(), fieldDate: '2022-06-12', birth: timestampDate, dates: { createdBy: 'Lula', createdAt: new Date(), startAt: 23423523423, finishAt: '2022-06-12', }, }, expecting: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: expect.any(TIPO), birth: expect.any(TIPO), dates: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, }; }, }; const newDate = new Date(); const firebaseTimestamp = (date = new Date()) => firestore_1.Timestamp.fromDate(date); exports.DEEP_OBJECT = { obj: { name: 'Pedro', date: newDate, fieldDate: '2022-06-12', visible: false, updatedAt: undefined, createdAt: null, birth: firebaseTimestamp(), custom_field: '23435', custom_field_2: '2022-06-12', defaultDateType: newDate, defaultTimestampType: firebaseTimestamp(), dates: { createdBy: 'Lula', createdAt: newDate, startAt: 23423523423, finishAt: '2022-06-12', fechas: { createdBy: 'Lula', createdAt: newDate, startAt: 23423523423, finishAt: '2022-06-12', posts: [ { id: 1, createdBy: 'Jow Dea', createdAt: newDate, startAt: 23423523423, finishAt: '2022-06-12', }, ], }, }, }, expecting: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: expect.any(TIPO), visible: false, updatedAt: undefined, createdAt: null, birth: expect.any(TIPO), custom_field: '23435', custom_field_2: '2022-06-12', defaultDateType: expect.any(TIPO), defaultTimestampType: expect.any(TIPO), dates: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), fechas: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), posts: [ { id: expect.any(Number), createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, ], }, }, }; }, expectingNull: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: expect.any(TIPO), visible: false, updatedAt: null, createdAt: null, birth: expect.any(TIPO), custom_field: '23435', custom_field_2: '2022-06-12', defaultDateType: expect.any(TIPO), defaultTimestampType: expect.any(TIPO), dates: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), fechas: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), posts: [ { id: expect.any(Number), createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, ], }, }, }; }, expectingCustomFields: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: expect.any(TIPO), visible: false, updatedAt: undefined, createdAt: null, birth: expect.any(TIPO), custom_field: expect.any(TIPO), custom_field_2: '2022-06-12', defaultDateType: expect.any(TIPO), defaultTimestampType: expect.any(TIPO), dates: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), fechas: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), posts: [ { id: expect.any(Number), createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, ], }, }, }; }, expectingAvoidCustomFields: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: '2022-06-12', visible: false, updatedAt: undefined, createdAt: null, birth: expect.any(TIPO), custom_field: '23435', custom_field_2: '2022-06-12', defaultDateType: expect.any(TIPO), defaultTimestampType: expect.any(TIPO), dates: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), fechas: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), posts: [ { id: expect.any(Number), createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, ], }, }, }; }, expectingIgnoreDateTypes: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: expect.any(TIPO), visible: false, updatedAt: undefined, createdAt: null, birth: expect.any(TIPO), custom_field: '23435', custom_field_2: '2022-06-12', defaultDateType: expect.any(Date), defaultTimestampType: expect.any(TIPO), dates: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), fechas: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), posts: [ { id: expect.any(Number), createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, ], }, }, }; }, expectingIgnoreTimestampTypes: (TIPO) => { return { name: expect.any(String), date: expect.any(TIPO), fieldDate: expect.any(TIPO), visible: false, updatedAt: undefined, createdAt: null, birth: expect.any(TIPO), custom_field: '23435', custom_field_2: '2022-06-12', defaultDateType: expect.any(TIPO), defaultTimestampType: expect.any(firestore_1.Timestamp), dates: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), fechas: { createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), posts: [ { id: expect.any(Number), createdBy: expect.any(String), createdAt: expect.any(TIPO), startAt: expect.any(TIPO), finishAt: expect.any(TIPO), }, ], }, }, }; }, };