Browse Source

test(server): Add tests relating to ProductVariant tax rate

Michael Bromley 7 years ago
parent
commit
9aa4aa7ee4
1 changed files with 46 additions and 0 deletions
  1. 46 0
      server/e2e/product.e2e-spec.ts

+ 46 - 0
server/e2e/product.e2e-spec.ts

@@ -132,6 +132,28 @@ describe('Product resolver', () => {
             expect(result.product.variants.length).toBe(2);
         });
 
+        it('ProductVariant price properties are correct', async () => {
+            const result = await client.query<GetProductWithVariants.Query, GetProductWithVariants.Variables>(
+                GET_PRODUCT_WITH_VARIANTS,
+                {
+                    languageCode: LanguageCode.en,
+                    id: 'T_2',
+                },
+            );
+
+            if (!result.product) {
+                fail('Product not found');
+                return;
+            }
+            expect(result.product.variants[0].priceBeforeTax).toBe(621);
+            expect(result.product.variants[0].price).toBe(745);
+            expect(result.product.variants[0].taxCategory).toEqual({
+                id: 'T_1',
+                name: 'Standard Tax',
+                taxRate: 20,
+            });
+        });
+
         it('returns null when id not found', async () => {
             const result = await client.query<GetProductWithVariants.Query, GetProductWithVariants.Variables>(
                 GET_PRODUCT_WITH_VARIANTS,
@@ -453,6 +475,30 @@ describe('Product resolver', () => {
                 expect(updatedVariant.price).toBe(432);
             });
 
+            it('updateProductVariants updates taxCategory and priceBeforeTax', async () => {
+                const firstVariant = variants[0];
+                const result = await client.query<
+                    UpdateProductVariants.Mutation,
+                    UpdateProductVariants.Variables
+                >(UPDATE_PRODUCT_VARIANTS, {
+                    input: [
+                        {
+                            id: firstVariant.id,
+                            price: 105,
+                            taxCategoryId: 'T_2',
+                        },
+                    ],
+                });
+                const updatedVariant = result.updateProductVariants[0];
+                if (!updatedVariant) {
+                    fail('no updated variant returned.');
+                    return;
+                }
+                expect(updatedVariant.price).toBe(105);
+                expect(updatedVariant.taxCategory.id).toBe('T_2');
+                expect(updatedVariant.priceBeforeTax).toBe(100);
+            });
+
             it('updateProductVariants throws with an invalid variant id', async () => {
                 try {
                     await client.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(