Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODECOV BA DEMO: Added NotEnoughInventory exception #660

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions react/src/components/NotEnoughInventory.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import './complete.css';
import { Link } from 'react-router-dom';

function NotEnoughInventory() {
return (
<div className="not-enough-inventory">
<h2>Not Enough Inventory</h2>
<p>
The product you are interested is out of stock.Please accept our deepest
apologies. If you want to know when it will be available, please <Link to="/">contact us</Link>.
</p>
</div>
);
}

export default NotEnoughInventory;
2 changes: 2 additions & 0 deletions react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import CompleteError from './components/CompleteError';
import Employee from './components/Employee';
import Home from './components/Home';
import NotFound from './components/NotFound';
import NotEnoughInventory from './components/NotEnoughInventory';
import Product from './components/Product';
import Products from './components/Products';
import ProductsJoin from './components/ProductsJoin';
Expand Down Expand Up @@ -360,6 +361,7 @@ class App extends Component {
path="/products-join"
element={<ProductsJoin backend={BACKEND_URL} />}
></Route>
<Route path="/not-enough-inventory" element={<NotEnoughInventory />} />NotEnoughInventory
<Route path="*" element={<NotFound />} />
</SentryRoutes>
</div>
Expand Down
14 changes: 12 additions & 2 deletions react/src/tests/Errors.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { crasher, UnhandledException } from '../utils/errors';
import { crasher, UnhandledException, InventoryException } from '../utils/errors';
import { createBrowserHistory } from 'history';

describe('Errors module', () => {
Expand Down Expand Up @@ -40,11 +40,21 @@ describe('Errors module', () => {
expect(() => crasher()).toThrow(RangeError);
});

test('should throw an UnhandledException when "crash" is true and errnum is 4', () => {
test('should throw a RangeError when "crash" is true and errnum is 4', () => {
setQueryParams({ crash: 'true', errnum: '4' });
expect(() => crasher()).toThrow(RangeError);
});

test('should throw an UnhandledException when "crash" is true and errnum is 5', () => {
setQueryParams({ crash: 'true', errnum: '5' });
expect(() => crasher()).toThrow(UnhandledException);
});

test('should throw an InventoryException when "crash" is true and errnum is 6', () => {
setQueryParams({ crash: 'true', errnum: '6' });
expect(() => crasher()).toThrow(InventoryException);
});

// This test is failing, need to look into this later
// test('should log the queryParam if empty', () => {
// setQueryParams({});
Expand Down
17 changes: 16 additions & 1 deletion react/src/utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ const syntaxError = () => eval('foo bar');
const rangeError = () => {
throw new RangeError('Parameter must be between 1 and 100');
};
const smallRangeError = () => {
throw new RangeError('Parameter must be between 1 and 10');
};
const unhandledError = () => {
throw new UnhandledException('unhandled error');
};
const inventoryError = () => {
throw new InventoryException('unhandled error');
};

const randomErrors = [
notAFunctionError,
referenceError,
syntaxError,
rangeError,
smallRangeError,
unhandledError,
inventoryError,
];

const throwErrorNumber = (i) => {
Expand Down Expand Up @@ -61,4 +69,11 @@ class UnhandledException extends Error {
}
}

export { crasher, UnhandledException };
class InventoryException extends Error {
constructor(message, functionName) {
super(message);
}
}


export { crasher, UnhandledException, InventoryException };
Loading