Skip to content

Commit

Permalink
GH-13939 OCC and state implementations for order history
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHi committed Oct 5, 2021
1 parent 636ad92 commit 0243e62
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export abstract class ConfiguratorTextfieldAdapter {
parameters: CommonConfigurator.ReadConfigurationFromCartEntryParameters
): Observable<ConfiguratorTextfield.Configuration>;

/**
* Abstract method to read a configuration for an order entry
*
* @param parameters read from order entry parameters object
* @returns Observable of configurations
*/
abstract readConfigurationForOrderEntry(
parameters: CommonConfigurator.ReadConfigurationFromOrderEntryParameters
): Observable<ConfiguratorTextfield.Configuration>;

/**
* Abstract method to update a configuration attached to a cart entry
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class MockConfiguratorTextfieldAdapter implements ConfiguratorTextfieldAdapter {
(params: CommonConfigurator.ReadConfigurationFromCartEntryParameters) =>
of('readConfigurationForCartEntry' + params)
);
readConfigurationForOrderEntry = createSpy().and.callFake(
(params: CommonConfigurator.ReadConfigurationFromOrderEntryParameters) =>
of('readConfigurationForOrderEntry' + params)
);
}

describe('ConfiguratorTextfieldConnector', () => {
Expand Down Expand Up @@ -88,10 +92,9 @@ describe('ConfiguratorTextfieldConnector', () => {
ConfiguratorTextfieldAdapter as Type<ConfiguratorTextfieldAdapter>
);

const params: CommonConfigurator.ReadConfigurationFromCartEntryParameters =
{
owner: ConfiguratorModelUtils.createInitialOwner(),
};
const params: CommonConfigurator.ReadConfigurationFromCartEntryParameters = {
owner: ConfiguratorModelUtils.createInitialOwner(),
};
let result;
service
.readConfigurationForCartEntry(params)
Expand All @@ -100,6 +103,22 @@ describe('ConfiguratorTextfieldConnector', () => {
expect(adapter.readConfigurationForCartEntry).toHaveBeenCalledWith(params);
});

it('should call adapter on readConfigurationForOrderEntry', () => {
const adapter = TestBed.inject(
ConfiguratorTextfieldAdapter as Type<ConfiguratorTextfieldAdapter>
);

const params: CommonConfigurator.ReadConfigurationFromOrderEntryParameters = {
owner: ConfiguratorModelUtils.createInitialOwner(),
};
let result;
service
.readConfigurationForOrderEntry(params)
.subscribe((res) => (result = res));
expect(result).toBe('readConfigurationForOrderEntry' + params);
expect(adapter.readConfigurationForOrderEntry).toHaveBeenCalledWith(params);
});

it('should call adapter on addToCart', () => {
const adapter = TestBed.inject(
ConfiguratorTextfieldAdapter as Type<ConfiguratorTextfieldAdapter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export class ConfiguratorTextfieldConnector {
): Observable<ConfiguratorTextfield.Configuration> {
return this.adapter.readConfigurationForCartEntry(parameters);
}
/**
* Reads an existing configuration for an order entry
* @param parameters Attributes needed to read a product configuration for an order entry
* @returns Observable of product configurations
*/
readConfigurationForOrderEntry(
parameters: CommonConfigurator.ReadConfigurationFromOrderEntryParameters
): Observable<ConfiguratorTextfield.Configuration> {
return this.adapter.readConfigurationForOrderEntry(parameters);
}
/**
* Updates a configuration that is attached to a cart entry
* @param parameters Attributes needed to update a cart entries' configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export const READ_CART_ENTRY_CONFIGURATION_FAIL =
'[Configurator] Read cart entry configuration Textfield Fail';
export const READ_CART_ENTRY_CONFIGURATION_SUCCESS =
'[Configurator] Read cart entry configuration Textfield Success';
export const READ_ORDER_ENTRY_CONFIGURATION =
'[Configurator] Read order entry configuration textfield';
export const READ_ORDER_ENTRY_CONFIGURATION_FAIL =
'[Configurator] Read order entry configuration textfield Fail';
export const READ_ORDER_ENTRY_CONFIGURATION_SUCCESS =
'[Configurator] Read order entry configuration textfield Success';
export const UPDATE_CART_ENTRY_CONFIGURATION =
'[Configurator] Update cart entry configuration Textfield';
export const UPDATE_CART_ENTRY_CONFIGURATION_FAIL =
Expand Down Expand Up @@ -108,6 +114,29 @@ export class ReadCartEntryConfigurationFail extends StateUtils.LoaderFailAction
}
}

export class ReadOrderEntryConfiguration extends StateUtils.LoaderLoadAction {
readonly type = READ_ORDER_ENTRY_CONFIGURATION;
constructor(
public payload: CommonConfigurator.ReadConfigurationFromOrderEntryParameters
) {
super(CONFIGURATION_TEXTFIELD_DATA);
}
}

export class ReadOrderEntryConfigurationSuccess extends StateUtils.LoaderSuccessAction {
readonly type = READ_ORDER_ENTRY_CONFIGURATION_SUCCESS;
constructor(public payload: ConfiguratorTextfield.Configuration) {
super(CONFIGURATION_TEXTFIELD_DATA);
}
}

export class ReadOrderEntryConfigurationFail extends StateUtils.LoaderFailAction {
readonly type = READ_ORDER_ENTRY_CONFIGURATION_FAIL;
constructor(public payload: any) {
super(CONFIGURATION_TEXTFIELD_DATA, payload);
}
}

export class RemoveConfiguration extends StateUtils.LoaderResetAction {
readonly type = REMOVE_CONFIGURATION;
constructor() {
Expand All @@ -123,5 +152,8 @@ export type ConfiguratorActions =
| ReadCartEntryConfigurationFail
| ReadCartEntryConfigurationSuccess
| ReadCartEntryConfiguration
| ReadOrderEntryConfigurationFail
| ReadOrderEntryConfigurationSuccess
| ReadOrderEntryConfiguration
| UpdateCartEntryConfiguration
| RemoveConfiguration;
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const cartModification: CartModification = {
describe('ConfiguratorTextfieldEffect', () => {
let createMock: jasmine.Spy;
let readFromCartEntryMock: jasmine.Spy;
let readFromOrderEntryMock: jasmine.Spy;
let addToCartMock: jasmine.Spy;
let updateCartEntryMock: jasmine.Spy;

Expand All @@ -60,6 +61,9 @@ describe('ConfiguratorTextfieldEffect', () => {
readFromCartEntryMock = jasmine
.createSpy()
.and.returnValue(of(productConfiguration));
readFromOrderEntryMock = jasmine
.createSpy()
.and.returnValue(of(productConfiguration));
addToCartMock = jasmine.createSpy().and.returnValue(of(cartModification));
updateCartEntryMock = jasmine
.createSpy()
Expand All @@ -68,6 +72,7 @@ describe('ConfiguratorTextfieldEffect', () => {
createConfiguration = createMock;
addToCart = addToCartMock;
readConfigurationForCartEntry = readFromCartEntryMock;
readConfigurationForOrderEntry = readFromOrderEntryMock;
updateConfigurationForCartEntry = updateCartEntryMock;
}

Expand Down Expand Up @@ -109,10 +114,9 @@ describe('ConfiguratorTextfieldEffect', () => {
payloadInput
);

const completion =
new ConfiguratorTextfieldActions.CreateConfigurationSuccess(
productConfiguration
);
const completion = new ConfiguratorTextfieldActions.CreateConfigurationSuccess(
productConfiguration
);
actions$ = hot('-a', { a: action });
const expected = cold('-b', { b: completion });

Expand All @@ -129,29 +133,26 @@ describe('ConfiguratorTextfieldEffect', () => {
payloadInput
);

const completionFailure =
new ConfiguratorTextfieldActions.CreateConfigurationFail(
normalizeHttpError(errorResponse)
);
const completionFailure = new ConfiguratorTextfieldActions.CreateConfigurationFail(
normalizeHttpError(errorResponse)
);
actions$ = hot('-a', { a: action });
const expected = cold('-b', { b: completionFailure });

expect(configEffects.createConfiguration$).toBeObservable(expected);
});

it('should emit a success action with content for an action of type readConfigurationFromCart if read from cart is successful', () => {
const payloadInput: CommonConfigurator.ReadConfigurationFromCartEntryParameters =
{
owner: ConfiguratorModelUtils.createInitialOwner(),
};
const payloadInput: CommonConfigurator.ReadConfigurationFromCartEntryParameters = {
owner: ConfiguratorModelUtils.createInitialOwner(),
};
const action = new ConfiguratorTextfieldActions.ReadCartEntryConfiguration(
payloadInput
);

const completion =
new ConfiguratorTextfieldActions.ReadCartEntryConfigurationSuccess(
productConfiguration
);
const completion = new ConfiguratorTextfieldActions.ReadCartEntryConfigurationSuccess(
productConfiguration
);
actions$ = hot('-a', { a: action });
const expectedObs = cold('-b', { b: completion });

Expand All @@ -162,18 +163,16 @@ describe('ConfiguratorTextfieldEffect', () => {

it('should emit a fail action in case read from cart leads to an error', () => {
readFromCartEntryMock.and.returnValue(throwError(errorResponse));
const payloadInput: CommonConfigurator.ReadConfigurationFromCartEntryParameters =
{
owner: ConfiguratorModelUtils.createInitialOwner(),
};
const payloadInput: CommonConfigurator.ReadConfigurationFromCartEntryParameters = {
owner: ConfiguratorModelUtils.createInitialOwner(),
};
const action = new ConfiguratorTextfieldActions.ReadCartEntryConfiguration(
payloadInput
);

const completionFailure =
new ConfiguratorTextfieldActions.ReadCartEntryConfigurationFail(
normalizeHttpError(errorResponse)
);
const completionFailure = new ConfiguratorTextfieldActions.ReadCartEntryConfigurationFail(
normalizeHttpError(errorResponse)
);
actions$ = hot('-a', { a: action });
const expectedObs = cold('-b', { b: completionFailure });

Expand All @@ -182,6 +181,45 @@ describe('ConfiguratorTextfieldEffect', () => {
);
});

it('should emit a success action with content for an action of type readOrderEntryConfiguration if read from order entry is successful', () => {
const payloadInput: CommonConfigurator.ReadConfigurationFromOrderEntryParameters = {
owner: ConfiguratorModelUtils.createInitialOwner(),
};
const action = new ConfiguratorTextfieldActions.ReadOrderEntryConfiguration(
payloadInput
);

const completion = new ConfiguratorTextfieldActions.ReadOrderEntryConfigurationSuccess(
productConfiguration
);
actions$ = cold('-a', { a: action });
const expectedObs = cold('-b', { b: completion });

expect(configEffects.readConfigurationForOrderEntry$).toBeObservable(
expectedObs
);
});

it('should emit a fail action in case read from order entry leads to an error', () => {
readFromOrderEntryMock.and.returnValue(throwError(errorResponse));
const payloadInput: CommonConfigurator.ReadConfigurationFromOrderEntryParameters = {
owner: ConfiguratorModelUtils.createInitialOwner(),
};
const action = new ConfiguratorTextfieldActions.ReadOrderEntryConfiguration(
payloadInput
);

const completionFailure = new ConfiguratorTextfieldActions.ReadOrderEntryConfigurationFail(
normalizeHttpError(errorResponse)
);
actions$ = cold('-a', { a: action });
const expectedObs = cold('-b', { b: completionFailure });

expect(configEffects.readConfigurationForOrderEntry$).toBeObservable(
expectedObs
);
});

it('createConfiguration must not emit anything in case source action is not covered', () => {
const action = new ConfiguratorTextfieldActions.CreateConfigurationSuccess({
configurationInfos: [],
Expand All @@ -208,8 +246,7 @@ describe('ConfiguratorTextfieldEffect', () => {
userId: userId,
});

const removeConfiguration =
new ConfiguratorTextfieldActions.RemoveConfiguration();
const removeConfiguration = new ConfiguratorTextfieldActions.RemoveConfiguration();

actions$ = hot('-a', { a: action });
const expected = cold('-(bc)', {
Expand Down Expand Up @@ -250,17 +287,15 @@ describe('ConfiguratorTextfieldEffect', () => {
cartEntryNumber: cartEntryNumber,
configuration: productConfiguration,
};
const action =
new ConfiguratorTextfieldActions.UpdateCartEntryConfiguration(
payloadInput
);
const action = new ConfiguratorTextfieldActions.UpdateCartEntryConfiguration(
payloadInput
);
const loadCart = new CartActions.LoadCart({
userId: userId,
cartId: cartId,
});

const removeConfiguration =
new ConfiguratorTextfieldActions.RemoveConfiguration();
const removeConfiguration = new ConfiguratorTextfieldActions.RemoveConfiguration();

actions$ = hot('-a', { a: action });
const expected = cold('-(bc)', {
Expand All @@ -278,14 +313,12 @@ describe('ConfiguratorTextfieldEffect', () => {
cartEntryNumber: cartEntryNumber,
configuration: productConfiguration,
};
const action =
new ConfiguratorTextfieldActions.UpdateCartEntryConfiguration(
payloadInput
);
const cartUpdateFail =
new ConfiguratorTextfieldActions.UpdateCartEntryConfigurationFail(
normalizeHttpError(errorResponse)
);
const action = new ConfiguratorTextfieldActions.UpdateCartEntryConfiguration(
payloadInput
);
const cartUpdateFail = new ConfiguratorTextfieldActions.UpdateCartEntryConfigurationFail(
normalizeHttpError(errorResponse)
);

actions$ = hot('-a', { a: action });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,35 @@ export class ConfiguratorTextfieldEffects {
)
);

@Effect()
readConfigurationForOrderEntry$: Observable<
| ConfiguratorTextfieldActions.ReadOrderEntryConfigurationSuccess
| ConfiguratorTextfieldActions.ReadOrderEntryConfigurationFail
> = this.actions$.pipe(
ofType(ConfiguratorTextfieldActions.READ_ORDER_ENTRY_CONFIGURATION),
switchMap(
(action: ConfiguratorTextfieldActions.ReadOrderEntryConfiguration) => {
const parameters: CommonConfigurator.ReadConfigurationFromOrderEntryParameters =
action.payload;

return this.configuratorTextfieldConnector
.readConfigurationForOrderEntry(parameters)
.pipe(
switchMap((result: ConfiguratorTextfield.Configuration) => [
new ConfiguratorTextfieldActions.ReadOrderEntryConfigurationSuccess(
result
),
]),
catchError((error) => [
new ConfiguratorTextfieldActions.ReadOrderEntryConfigurationFail(
normalizeHttpError(error)
),
])
);
}
)
);

constructor(
private actions$: Actions,
private configuratorTextfieldConnector: ConfiguratorTextfieldConnector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function defaultOccConfiguratorTextfieldConfigFactory(): OccConfig {

readTextfieldConfigurationForCartEntry:
'users/${userId}/carts/${cartId}/entries/${cartEntryNumber}/configurator/textfield',

readTextfieldConfigurationForOrderEntry:
'users/${userId}/orders/${orderId}/entries/${orderEntryNumber}/configurator/textfield',
updateTextfieldConfigurationForCartEntry:
'users/${userId}/carts/${cartId}/entries/${cartEntryNumber}/configurator/textfield',
},
Expand Down
Loading

0 comments on commit 0243e62

Please sign in to comment.