list-query-builder.e2e-spec.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { mergeConfig } from '@vendure/core';
  2. import { createTestEnvironment } from '@vendure/testing';
  3. import gql from 'graphql-tag';
  4. import path from 'path';
  5. import { initialData } from '../../../e2e-common/e2e-initial-data';
  6. import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
  7. import { ListQueryPlugin } from './fixtures/test-plugins/list-query-plugin';
  8. import { fixPostgresTimezone } from './utils/fix-pg-timezone';
  9. fixPostgresTimezone();
  10. describe('ListQueryBuilder', () => {
  11. const { server, adminClient } = createTestEnvironment(
  12. mergeConfig(testConfig, {
  13. plugins: [ListQueryPlugin],
  14. }),
  15. );
  16. beforeAll(async () => {
  17. await server.init({
  18. initialData,
  19. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  20. customerCount: 1,
  21. });
  22. await adminClient.asSuperAdmin();
  23. }, TEST_SETUP_TIMEOUT_MS);
  24. afterAll(async () => {
  25. await server.destroy();
  26. });
  27. function getItemLabels(items: any[]): string[] {
  28. return items.map((x: any) => x.label).sort();
  29. }
  30. describe('date filtering', () => {
  31. it('before', async () => {
  32. const { testEntities } = await adminClient.query(GET_LIST, {
  33. options: {
  34. filter: {
  35. date: {
  36. before: '2020-01-20T10:00:00.000Z',
  37. },
  38. },
  39. },
  40. });
  41. expect(getItemLabels(testEntities.items)).toEqual(['A', 'B']);
  42. });
  43. it('before on same date', async () => {
  44. const { testEntities } = await adminClient.query(GET_LIST, {
  45. options: {
  46. filter: {
  47. date: {
  48. before: '2020-01-15T17:00:00.000Z',
  49. },
  50. },
  51. },
  52. });
  53. expect(getItemLabels(testEntities.items)).toEqual(['A', 'B']);
  54. });
  55. it('after', async () => {
  56. const { testEntities } = await adminClient.query(GET_LIST, {
  57. options: {
  58. filter: {
  59. date: {
  60. after: '2020-01-20T10:00:00.000Z',
  61. },
  62. },
  63. },
  64. });
  65. expect(getItemLabels(testEntities.items)).toEqual(['C']);
  66. });
  67. it('after on same date', async () => {
  68. const { testEntities } = await adminClient.query(GET_LIST, {
  69. options: {
  70. filter: {
  71. date: {
  72. after: '2020-01-25T09:00:00.000Z',
  73. },
  74. },
  75. },
  76. });
  77. expect(getItemLabels(testEntities.items)).toEqual(['C']);
  78. });
  79. it('between', async () => {
  80. const { testEntities } = await adminClient.query(GET_LIST, {
  81. options: {
  82. filter: {
  83. date: {
  84. between: {
  85. start: '2020-01-10T10:00:00.000Z',
  86. end: '2020-01-20T10:00:00.000Z',
  87. },
  88. },
  89. },
  90. },
  91. });
  92. expect(getItemLabels(testEntities.items)).toEqual(['B']);
  93. });
  94. });
  95. });
  96. const GET_LIST = gql`
  97. query GetTestEntities($options: TestEntityListOptions) {
  98. testEntities(options: $options) {
  99. totalItems
  100. items {
  101. id
  102. label
  103. date
  104. }
  105. }
  106. }
  107. `;