| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import { mergeConfig } from '@vendure/core';
- import { createTestEnvironment } from '@vendure/testing';
- import gql from 'graphql-tag';
- import path from 'path';
- import { initialData } from '../../../e2e-common/e2e-initial-data';
- import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
- import { ListQueryPlugin } from './fixtures/test-plugins/list-query-plugin';
- import { fixPostgresTimezone } from './utils/fix-pg-timezone';
- fixPostgresTimezone();
- describe('ListQueryBuilder', () => {
- const { server, adminClient } = createTestEnvironment(
- mergeConfig(testConfig, {
- plugins: [ListQueryPlugin],
- }),
- );
- beforeAll(async () => {
- await server.init({
- initialData,
- productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
- customerCount: 1,
- });
- await adminClient.asSuperAdmin();
- }, TEST_SETUP_TIMEOUT_MS);
- afterAll(async () => {
- await server.destroy();
- });
- function getItemLabels(items: any[]): string[] {
- return items.map((x: any) => x.label).sort();
- }
- describe('date filtering', () => {
- it('before', async () => {
- const { testEntities } = await adminClient.query(GET_LIST, {
- options: {
- filter: {
- date: {
- before: '2020-01-20T10:00:00.000Z',
- },
- },
- },
- });
- expect(getItemLabels(testEntities.items)).toEqual(['A', 'B']);
- });
- it('before on same date', async () => {
- const { testEntities } = await adminClient.query(GET_LIST, {
- options: {
- filter: {
- date: {
- before: '2020-01-15T17:00:00.000Z',
- },
- },
- },
- });
- expect(getItemLabels(testEntities.items)).toEqual(['A', 'B']);
- });
- it('after', async () => {
- const { testEntities } = await adminClient.query(GET_LIST, {
- options: {
- filter: {
- date: {
- after: '2020-01-20T10:00:00.000Z',
- },
- },
- },
- });
- expect(getItemLabels(testEntities.items)).toEqual(['C']);
- });
- it('after on same date', async () => {
- const { testEntities } = await adminClient.query(GET_LIST, {
- options: {
- filter: {
- date: {
- after: '2020-01-25T09:00:00.000Z',
- },
- },
- },
- });
- expect(getItemLabels(testEntities.items)).toEqual(['C']);
- });
- it('between', async () => {
- const { testEntities } = await adminClient.query(GET_LIST, {
- options: {
- filter: {
- date: {
- between: {
- start: '2020-01-10T10:00:00.000Z',
- end: '2020-01-20T10:00:00.000Z',
- },
- },
- },
- },
- });
- expect(getItemLabels(testEntities.items)).toEqual(['B']);
- });
- });
- });
- const GET_LIST = gql`
- query GetTestEntities($options: TestEntityListOptions) {
- testEntities(options: $options) {
- totalItems
- items {
- id
- label
- date
- }
- }
- }
- `;
|