custom-fields.e2e-spec.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import gql from 'graphql-tag';
  2. import path from 'path';
  3. import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
  4. import { GetProductList } from './graphql/generated-e2e-admin-types';
  5. import { GET_PRODUCT_LIST } from './graphql/shared-definitions';
  6. import { TestAdminClient, TestShopClient } from './test-client';
  7. import { TestServer } from './test-server';
  8. // tslint:disable:no-non-null-assertion
  9. describe('Custom fields', () => {
  10. const adminClient = new TestAdminClient();
  11. const shopClient = new TestShopClient();
  12. const server = new TestServer();
  13. beforeAll(async () => {
  14. await server.init({
  15. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  16. customerCount: 1,
  17. }, {
  18. customFields: {
  19. Product: [
  20. { name: 'foo', type: 'string' },
  21. ],
  22. },
  23. });
  24. await adminClient.init();
  25. await shopClient.init();
  26. }, TEST_SETUP_TIMEOUT_MS);
  27. afterAll(async () => {
  28. await server.destroy();
  29. });
  30. it('globalSettings.serverConfig.customFieldConfig', async () => {
  31. const { globalSettings } = await adminClient.query(gql`
  32. query {
  33. globalSettings {
  34. serverConfig {
  35. customFieldConfig {
  36. Product {
  37. name
  38. type
  39. }
  40. }
  41. }
  42. }
  43. }
  44. `);
  45. expect(globalSettings.serverConfig.customFieldConfig).toEqual({
  46. Product: [
  47. { name: 'foo', type: 'string' },
  48. ],
  49. });
  50. });
  51. it('works', async () => {
  52. const { products } = await adminClient.query(gql`
  53. query GetProductsCustomFields {
  54. products {
  55. items {
  56. id
  57. name
  58. customFields {
  59. foo
  60. }
  61. }
  62. }
  63. }`, {
  64. options: {},
  65. });
  66. expect(products.items).toEqual([
  67. {
  68. id: 'T_1',
  69. name: 'Laptop',
  70. customFields: {
  71. foo: null,
  72. },
  73. },
  74. ]);
  75. });
  76. });