Procházet zdrojové kódy

chore(dev-server): Commit test plugins

Michael Bromley před 4 roky
rodič
revize
43213e5f15

+ 56 - 0
packages/dev-server/test-plugins/sso-auth-strategy.ts

@@ -0,0 +1,56 @@
+import { HttpService } from '@nestjs/common';
+import {
+    AuthenticationStrategy,
+    ExternalAuthenticationService,
+    Injector,
+    Logger,
+    RequestContext,
+    RoleService,
+    User,
+} from '@vendure/core';
+import { DocumentNode } from 'graphql';
+import gql from 'graphql-tag';
+
+export type SSOAuthData = {
+    email: string;
+};
+
+export class SSOShopAuthenticationStrategy implements AuthenticationStrategy<SSOAuthData> {
+    readonly name = 'ssoShop';
+    private externalAuthenticationService: ExternalAuthenticationService;
+    private httpService: HttpService;
+    private roleService: RoleService;
+
+    init(injector: Injector) {
+        this.externalAuthenticationService = injector.get(ExternalAuthenticationService);
+        this.httpService = injector.get(HttpService);
+        this.roleService = injector.get(RoleService);
+    }
+
+    defineInputType(): DocumentNode {
+        return gql`
+            input SSOAuthInput {
+                email: String!
+            }
+        `;
+    }
+
+    async authenticate(ctx: RequestContext, data: SSOAuthData): Promise<User | false> {
+        if (data.email !== 'test@test.com') {
+            return false;
+        }
+        const user = await this.externalAuthenticationService.findCustomerUser(ctx, this.name, data.email);
+        if (user) {
+            return user;
+        }
+
+        return this.externalAuthenticationService.createCustomerAndUser(ctx, {
+            strategy: this.name,
+            externalIdentifier: data.email,
+            emailAddress: data.email,
+            firstName: 'test',
+            lastName: 'customer',
+            verified: true,
+        });
+    }
+}

+ 78 - 0
packages/dev-server/test-plugins/typeorm-issue-plugin.ts

@@ -0,0 +1,78 @@
+import { Args, Query, Resolver } from '@nestjs/graphql';
+import {
+    Ctx,
+    ListQueryBuilder,
+    PluginCommonModule,
+    ProductVariant,
+    RequestContext,
+    TransactionalConnection,
+    translateDeep,
+    VendurePlugin,
+} from '@vendure/core';
+import { gql } from 'apollo-server-core';
+
+// Testing this issue https://github.com/typeorm/typeorm/issues/7707
+@Resolver()
+export class TestResolver {
+    constructor(private connection: TransactionalConnection, private listQueryBuilder: ListQueryBuilder) {}
+
+    @Query()
+    test(@Ctx() ctx: RequestContext, @Args() args: any) {
+        const relations = [
+            'options',
+            'facetValues',
+            'facetValues.facet',
+            'taxCategory',
+            'assets',
+            'featuredAsset',
+        ];
+
+        return this.listQueryBuilder
+            .build(
+                ProductVariant,
+                {},
+                {
+                    relations,
+                    orderBy: { id: 'ASC' },
+                    where: { deletedAt: null },
+                    ctx,
+                },
+            )
+            .innerJoinAndSelect('productvariant.channels', 'channel', 'channel.id = :channelId', {
+                channelId: ctx.channelId,
+            })
+            .innerJoinAndSelect('productvariant.product', 'product', 'product.id = :productId', {
+                id: args.id,
+            })
+            .getManyAndCount()
+            .then(async ([variants, totalItems]) => {
+                const items = await Promise.all(
+                    variants.map(async variant => {
+                        return translateDeep(variant, ctx.languageCode, [
+                            'options',
+                            'facetValues',
+                            ['facetValues', 'facet'],
+                        ]);
+                    }),
+                );
+
+                return {
+                    items,
+                    totalItems,
+                };
+            });
+    }
+}
+
+@VendurePlugin({
+    imports: [PluginCommonModule],
+    shopApiExtensions: {
+        schema: gql`
+            extend type Query {
+                test(id: ID!): [ProductVariant!]!
+            }
+        `,
+        resolvers: [TestResolver],
+    },
+})
+export class TypeormIssuePlugin {}