Browse Source

test(core): Create (failing) tests for #1611

I've created a couple of tests for #1611 which are both failing
currently, as expected, but can be used to help figure out
a solution. Both tests are disabled with `xdescribe` for now.
Michael Bromley 3 years ago
parent
commit
35d8d79f31

+ 10 - 0
packages/core/e2e/fixtures/test-plugins/list-query-plugin.ts

@@ -26,6 +26,7 @@ export class TestEntity extends VendureEntity implements Translatable {
     constructor(input: Partial<TestEntity>) {
         super(input);
     }
+
     @Column()
     label: string;
 
@@ -155,6 +156,14 @@ export class ListQueryResolver {
 }
 
 const apiExtensions = gql`
+    type TestEntityTranslation implements Node {
+        id: ID!
+        createdAt: DateTime!
+        updatedAt: DateTime!
+        languageCode: LanguageCode!
+        name: String!
+    }
+
     type TestEntity implements Node {
         id: ID!
         createdAt: DateTime!
@@ -168,6 +177,7 @@ const apiExtensions = gql`
         descriptionLength: Int!
         price: Int!
         ownerId: ID!
+        translations: [TestEntityTranslation!]!
     }
 
     type TestEntityList implements PaginatedList {

+ 4 - 0
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -9591,6 +9591,10 @@ export namespace UpdateOrderCustomFields {
     export type Variables = UpdateOrderCustomFieldsMutationVariables;
     export type Mutation = UpdateOrderCustomFieldsMutation;
     export type SetOrderCustomFields = NonNullable<UpdateOrderCustomFieldsMutation['setOrderCustomFields']>;
+    export type OrderInlineFragment = { __typename: 'Order' } & Pick<
+        NonNullable<UpdateOrderCustomFieldsMutation['setOrderCustomFields']>,
+        'id'
+    >;
 }
 
 export namespace GetTagList {

+ 62 - 0
packages/core/e2e/list-query-builder.e2e-spec.ts

@@ -962,6 +962,50 @@ describe('ListQueryBuilder', () => {
             11, 9, 22, 14, 13, 33,
         ]);
     });
+
+    // https://github.com/vendure-ecommerce/vendure/issues/1611
+    xdescribe('translations handling', () => {
+        const allTranslations = [
+            [
+                { languageCode: LanguageCode.en, name: 'apple' },
+                { languageCode: LanguageCode.de, name: 'apfel' },
+            ],
+            [
+                { languageCode: LanguageCode.en, name: 'bike' },
+                { languageCode: LanguageCode.de, name: 'fahrrad' },
+            ],
+        ];
+        it('returns all translations with default languageCode', async () => {
+            const { testEntities } = await shopClient.query(GET_LIST_WITH_TRANSLATIONS, {
+                options: {
+                    take: 2,
+                    sort: {
+                        order: SortOrder.ASC,
+                    },
+                },
+            });
+
+            expect(testEntities.items.map((e: any) => e.name)).toEqual(['apple', 'bike']);
+            expect(testEntities.items.map((e: any) => e.translations)).toEqual(allTranslations);
+        });
+        it('returns all translations with non-default languageCode', async () => {
+            const { testEntities } = await shopClient.query(
+                GET_LIST_WITH_TRANSLATIONS,
+                {
+                    options: {
+                        take: 2,
+                        sort: {
+                            order: SortOrder.ASC,
+                        },
+                    },
+                },
+                { languageCode: LanguageCode.de },
+            );
+
+            expect(testEntities.items.map((e: any) => e.name)).toEqual(['apfel', 'fahrrad']);
+            expect(testEntities.items.map((e: any) => e.translations)).toEqual(allTranslations);
+        });
+    });
 });
 
 const GET_LIST = gql`
@@ -978,6 +1022,24 @@ const GET_LIST = gql`
     }
 `;
 
+const GET_LIST_WITH_TRANSLATIONS = gql`
+    query GetTestEntitiesWithTranslations($options: TestEntityListOptions) {
+        testEntities(options: $options) {
+            totalItems
+            items {
+                id
+                label
+                name
+                date
+                translations {
+                    languageCode
+                    name
+                }
+            }
+        }
+    }
+`;
+
 const GET_ARRAY_LIST = gql`
     query GetTestEntitiesArray($options: TestEntityListOptions) {
         testEntitiesGetMany(options: $options) {