| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- import { LanguageCode } from '@vendure/common/lib/generated-types';
- import gql from 'graphql-tag';
- import path from 'path';
- import { ConfigService } from '../src/config/config.service';
- import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
- import {
- TestAPIExtensionPlugin,
- TestPluginWithAllLifecycleHooks,
- TestPluginWithConfigAndBootstrap,
- TestPluginWithProvider,
- } from './fixtures/test-plugins';
- import { TestAdminClient, TestShopClient } from './test-client';
- import { TestServer } from './test-server';
- describe('Plugins', () => {
- const adminClient = new TestAdminClient();
- const shopClient = new TestShopClient();
- const server = new TestServer();
- const bootstrapMockFn = jest.fn();
- const onBootstrapFn = jest.fn();
- const onWorkerBootstrapFn = jest.fn();
- const onCloseFn = jest.fn();
- const onWorkerCloseFn = jest.fn();
- beforeAll(async () => {
- const token = await server.init(
- {
- productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
- customerCount: 1,
- },
- {
- plugins: [
- TestPluginWithAllLifecycleHooks.init(
- onBootstrapFn,
- onWorkerBootstrapFn,
- onCloseFn,
- onWorkerCloseFn,
- ),
- TestPluginWithConfigAndBootstrap.setup(bootstrapMockFn),
- TestAPIExtensionPlugin,
- TestPluginWithProvider,
- ],
- },
- );
- await adminClient.init();
- await shopClient.init();
- }, TEST_SETUP_TIMEOUT_MS);
- afterAll(async () => {
- await server.destroy();
- });
- it('calls onVendureBootstrap', () => {
- expect(onBootstrapFn).toHaveBeenCalled();
- });
- it('calls onWorkerVendureBootstrap', () => {
- expect(onWorkerBootstrapFn).toHaveBeenCalled();
- });
- it('can modify the config in configure()', () => {
- expect(bootstrapMockFn).toHaveBeenCalled();
- const configService: ConfigService = bootstrapMockFn.mock.calls[0][0];
- expect(configService instanceof ConfigService).toBe(true);
- expect(configService.defaultLanguageCode).toBe(LanguageCode.zh);
- });
- it('extends the admin API', async () => {
- const result = await adminClient.query(gql`
- query {
- foo
- }
- `);
- expect(result.foo).toEqual(['bar']);
- });
- it('extends the shop API', async () => {
- const result = await shopClient.query(gql`
- query {
- baz
- }
- `);
- expect(result.baz).toEqual(['quux']);
- });
- it('DI works with defined providers', async () => {
- const result = await shopClient.query(gql`
- query {
- names
- }
- `);
- expect(result.names).toEqual(['seon', 'linda', 'hong']);
- });
- describe('on app close', () => {
- beforeAll(async () => {
- await server.destroy();
- });
- it('calls onVendureClose', () => {
- expect(onCloseFn).toHaveBeenCalled();
- });
- it('calls onWorkerVendureClose', () => {
- expect(onWorkerCloseFn).toHaveBeenCalled();
- });
- });
- });
|