Skip to content

Commit

Permalink
added diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
nagesh-dixit committed Mar 20, 2024
1 parent c5b1f52 commit e8e4848
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ This Connector is to be used in self-learning training modules only. It contains
2. an event app that manages products in new arrivals
3. a cleanup job app that runs daily to remove products from the new arrivals category after 30 days


![Sample Connector Diagram](docs/images/sample-connector.png "Sample Connector")

## Prerequisite

- commercetools Composable Commerce account
Expand All @@ -26,7 +29,9 @@ Take note of the following:

## How to Install

Deploy this demo Connector into any project to learn and experience how commercetools Connect makes integrations quick and easy. This Connector contains three applications, each of a different type.
Deploy this demo Connector into any project to learn and experience how commercetools Connect makes integrations quick and easy. Follow the steps from the [commercetools connect deployment documentation](https://docs.commercetools.com/connect/concepts#deployments).

This Connector contains three applications, each of a different type.

### free-sample-product-service

Expand Down Expand Up @@ -56,3 +61,7 @@ Configurations:

1. Category key for new arrivals
2. API credentials

## How to Uninstall

In order to uninstall the connector, either send a DELETE [using API](https://docs.commercetools.com/connect/deployments#delete-deployment) or simply [uninstall it from the Merchant Center](https://docs.commercetools.com/merchant-center/connect#uninstall-a-connector).
Binary file added docs/images/sample-connector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions free-sample-product-service/src/utils/assert.utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { assert, assertError, assertString } from './assert.utils';

describe('assert', () => {
it('should not throw an error when the condition is true', () => {
expect(() => assert(true, 'Condition is true')).not.toThrow();
});

it('should throw an error when the condition is false', () => {
expect(() => assert(false, 'Condition is false')).toThrow(
'Assertion failed: Condition is false'
);
});
});

describe('assertError', () => {
it('should not throw an error when the value is an Error', () => {
const error = new Error('Test error');
expect(() => assertError(error, 'It is an Error')).not.toThrow();
});

it('should throw an error when the value is not an Error', () => {
const nonErrorValue = 'Not an error';
expect(() => assertError(nonErrorValue, 'Not an Error')).toThrow(
'Assertion failed: Not an Error'
);
});
});

describe('assertString', () => {
it('should not throw an error when the value is a string', () => {
const stringValue = 'Test string';
expect(() => assertString(stringValue, 'It is a string')).not.toThrow();
});

it('should throw an error when the value is not a string', () => {
const nonStringValue = 10;
expect(() => assertString(nonStringValue, 'It is a string')).toThrow(
'Assertion failed: It is a string'
);
});
});
47 changes: 47 additions & 0 deletions free-sample-product-service/src/utils/config.utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import CustomError from '../errors/custom.error';
import { readConfiguration } from './config.utils';
import * as validatorHelper from '../validators/helpers.validators';

// Mock .env
const mockEnv = {
CTP_CLIENT_ID: 'mockClientId',
CTP_CLIENT_SECRET: 'mockClientSecret',
CTP_PROJECT_KEY: 'mockProjectKey',
CTP_REGION: 'mockRegion',
SAMPLE_PRODUCT_QUANTITY: '100',
SAMPLE_PRODUCT_SKU: 'mockProductSku',
CHANNEL_KEY: 'mockChannelKey',
SAMPLE_LINEITEM_KEY: 'mockLineItemKey',
CART_MIN_VALUE: '10',
};

describe('readConfiguration', () => {
it('should return the correct configuration when env variables are valid', () => {
process.env = mockEnv
const expectedConfig = {
clientId: 'mockClientId',
clientSecret: 'mockClientSecret',
projectKey: 'mockProjectKey',
region: 'mockRegion',
freeSampleQuantity: parseInt('100' || ''),
freeSampleSku: 'mockProductSku',
freeSampleChannelKey: 'mockChannelKey',
freeLineItemKey: 'mockLineItemKey',
minCartValue: parseInt('10' || ''),
};

// Mock the validation function to return an empty array
jest.spyOn(validatorHelper, 'getValidateMessages').mockReturnValue([]);

const config = readConfiguration();
expect(config).toEqual(expectedConfig);
});

it('should throw a CustomError when env variables are invalid', () => {
process.env = mockEnv
// Mock the validation function to return validation errors
jest.spyOn(validatorHelper, 'getValidateMessages').mockReturnValue(['Invalid variable: CTP_CLIENT_ID']);

expect(() => {readConfiguration();}).toThrow(CustomError);
});
});
7 changes: 7 additions & 0 deletions free-sample-product-service/src/utils/logger.utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { logger } from "./logger.utils"

describe("logger object", () => {
it("should not throw an error when logger object", () => {
expect(typeof logger).toEqual('object');
});
});
2 changes: 1 addition & 1 deletion free-sample-product-service/tests/service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from '@jest/globals';

describe('Testing Cart Controller', () => {
test('POST `/service` route', async () => {
test('POST `/free-sample-product-service` route', async () => {
expect(1).toBe(1);
});
});

0 comments on commit e8e4848

Please sign in to comment.