Skip to content

Commit

Permalink
Fix broken state repo test
Browse files Browse the repository at this point in the history
Jira ticket: CAMS-283

Co-authored-by: James Brooks <[email protected]>
Co-authored-by: Brian Posey <[email protected]>,
  • Loading branch information
btposey and jamesobrooks committed Sep 20, 2024
1 parent 4e94837 commit 4e0c7f5
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { AggregateAuthenticationError } from '@azure/identity';
import { ServerConfigError } from '../../common-errors/server-config-error';
import {
MockHumbleItem,
MockHumbleItems,
MockHumbleQuery,
} from '../../testing/mock.cosmos-client-humble';
import { MockHumbleItems, MockHumbleQuery } from '../../testing/mock.cosmos-client-humble';
import { createMockApplicationContext } from '../../testing/testing-utilities';
import { OrderSyncState } from '../../use-cases/gateways.types';
import { ApplicationContext } from '../types/basic';
Expand Down Expand Up @@ -67,9 +63,9 @@ describe('Runtime State Repo', () => {
delete stateToCreate.id;
const created = await repo.createState(context, stateToCreate);

const replace = jest.spyOn(MockHumbleItem.prototype, 'replace');
const upsert = jest.spyOn(MockHumbleItems.prototype, 'upsert');
await repo.updateState(context, created);
expect(replace).toHaveBeenCalled();
expect(upsert).toHaveBeenCalled();
});

test('should throw a ServerConfigError if AggregateAuthenticationError is encountered', async () => {
Expand All @@ -81,8 +77,8 @@ describe('Runtime State Repo', () => {
const fetchAllSpy = jest
.spyOn(MockHumbleQuery.prototype, 'fetchAll')
.mockRejectedValue(cosmosdbAggregateError);
const replaceSpy = jest
.spyOn(MockHumbleItem.prototype, 'replace')
const upsertSpy = jest
.spyOn(MockHumbleItems.prototype, 'upsert')
.mockRejectedValue(cosmosdbAggregateError);
const createSpy = jest
.spyOn(MockHumbleItems.prototype, 'create')
Expand All @@ -91,7 +87,7 @@ describe('Runtime State Repo', () => {
await expect(repo.getState(context, 'ORDERS_SYNC_STATE')).rejects.toThrow(serverConfigError);
expect(fetchAllSpy).toHaveBeenCalled();
await expect(repo.updateState(context, expected)).rejects.toThrow(serverConfigError);
expect(replaceSpy).toHaveBeenCalled();
expect(upsertSpy).toHaveBeenCalled();
await expect(repo.createState(context, expected)).rejects.toThrow(serverConfigError);
expect(createSpy).toHaveBeenCalled();
});
Expand All @@ -101,13 +97,13 @@ describe('Runtime State Repo', () => {
const fetchAllSpy = jest
.spyOn(MockHumbleQuery.prototype, 'fetchAll')
.mockRejectedValue(someError);
const replaceSpy = jest.spyOn(MockHumbleItem.prototype, 'replace').mockRejectedValue(someError);
const upsertSpy = jest.spyOn(MockHumbleItems.prototype, 'upsert').mockRejectedValue(someError);
const createSpy = jest.spyOn(MockHumbleItems.prototype, 'create').mockRejectedValue(someError);

await expect(repo.getState(context, 'ORDERS_SYNC_STATE')).rejects.toThrow(someError);
expect(fetchAllSpy).toHaveBeenCalled();
await expect(repo.updateState(context, expected)).rejects.toThrow(someError);
expect(replaceSpy).toHaveBeenCalled();
expect(upsertSpy).toHaveBeenCalled();
await expect(repo.createState(context, expected)).rejects.toThrow(someError);
expect(createSpy).toHaveBeenCalled();
});
Expand Down

0 comments on commit 4e0c7f5

Please sign in to comment.