fix: timestamp queries (#2583)

This commit is contained in:
Dan Ribbens
2023-05-01 13:45:51 -04:00
committed by GitHub
parent 14a6b40bcc
commit 9c5107e86d
11 changed files with 647 additions and 272 deletions

View File

@@ -10,6 +10,7 @@ import { defaultText } from './collections/Text';
import { blocksFieldSeedData } from './collections/Blocks';
import { localizedTextValue, namedTabDefaultValue, namedTabText, tabsDoc, tabsSlug } from './collections/Tabs';
import { defaultNumber, numberDoc } from './collections/Number';
import { dateDoc } from './collections/Date';
let client;
let serverURL;
@@ -41,6 +42,45 @@ describe('Fields', () => {
});
});
describe('timestamps', () => {
const tenMinutesAgo = new Date(Date.now() - 1000 * 60 * 10);
let doc;
beforeAll(async () => {
doc = await payload.create({
collection: 'date-fields',
data: dateDoc,
});
});
it('should query updatedAt', async () => {
const { docs } = await payload.find({
collection: 'date-fields',
depth: 0,
where: {
updatedAt: {
greater_than_equal: tenMinutesAgo,
},
},
});
expect(docs.map(({ id }) => id)).toContain(doc.id);
});
it('should query createdAt', async () => {
const result = await payload.find({
collection: 'date-fields',
depth: 0,
where: {
createdAt: {
greater_than_equal: tenMinutesAgo,
},
},
});
expect(result.docs[0].id).toEqual(doc.id);
});
});
describe('select', () => {
let doc;
beforeAll(async () => {