From 7e9dd1e95d9f3a5b5e45792b14dd5e5b807a53fe Mon Sep 17 00:00:00 2001 From: Mark Fortes Date: Sat, 16 Nov 2024 15:53:25 -0600 Subject: [PATCH] vitest for posts.jsx --- coverage/.tmp/coverage-0.json | 1 + coverage/.tmp/coverage-1.json | 1 + src/utilities/posts.test.jsx | 76 +++++++++++++++++++++++++++++++++++ vite.config.js | 3 ++ 4 files changed, 81 insertions(+) create mode 100644 coverage/.tmp/coverage-0.json create mode 100644 coverage/.tmp/coverage-1.json create mode 100644 src/utilities/posts.test.jsx diff --git a/coverage/.tmp/coverage-0.json b/coverage/.tmp/coverage-0.json new file mode 100644 index 0000000..a3060f0 --- /dev/null +++ b/coverage/.tmp/coverage-0.json @@ -0,0 +1 @@ +{"result":[{"scriptId":"985","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/Cafes_Nearby.test.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":4826,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":4826,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1298,"endOffset":1363,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1376,"endOffset":1429,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1504,"endOffset":2032,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1597,"endOffset":2028,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1251","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/App.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":5369,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":5369,"count":1}],"isBlockCoverage":true},{"functionName":"App","ranges":[{"startOffset":962,"endOffset":3388,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1312","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/LandingPage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":6681,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":6681,"count":1}],"isBlockCoverage":true},{"functionName":"LandingPage","ranges":[{"startOffset":1271,"endOffset":3144,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1502,"endOffset":2019,"count":1}],"isBlockCoverage":true},{"functionName":"fetchData","ranges":[{"startOffset":1532,"endOffset":1997,"count":1},{"startOffset":1561,"endOffset":1574,"count":0},{"startOffset":1576,"endOffset":1991,"count":0}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2064,"endOffset":2099,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1314","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/App.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":486,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":486,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1315","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/MapComponent.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":9240,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":9240,"count":1}],"isBlockCoverage":true},{"functionName":"MapComponent","ranges":[{"startOffset":629,"endOffset":3194,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":910,"endOffset":1365,"count":1},{"startOffset":943,"endOffset":950,"count":0}],"isBlockCoverage":true},{"functionName":"initMap","ranges":[{"startOffset":971,"endOffset":1345,"count":1},{"startOffset":1054,"endOffset":1344,"count":0}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1406,"endOffset":2896,"count":1},{"startOffset":1427,"endOffset":1443,"count":0},{"startOffset":1452,"endOffset":2895,"count":0}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1585,"endOffset":2890,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1316","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/Banner.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":14734,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":14734,"count":1}],"isBlockCoverage":true},{"functionName":"Banner","ranges":[{"startOffset":1062,"endOffset":6718,"count":1},{"startOffset":4468,"endOffset":5313,"count":0},{"startOffset":5767,"endOffset":6079,"count":0}],"isBlockCoverage":true},{"functionName":"handleInputChange","ranges":[{"startOffset":1372,"endOffset":1654,"count":0}],"isBlockCoverage":false},{"functionName":"handleSelectCafe","ranges":[{"startOffset":1683,"endOffset":1793,"count":0}],"isBlockCoverage":false},{"functionName":"handleSearch","ranges":[{"startOffset":1818,"endOffset":2188,"count":0}],"isBlockCoverage":false},{"functionName":"","ranges":[{"startOffset":4588,"endOffset":5131,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":6814,"endOffset":6836,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1317","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/Banner.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":490,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":490,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1318","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/Icon.svg","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":555,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":555,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1319","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/Search.svg","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":565,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":565,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1320","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/firebase.js","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":17838,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":17838,"count":1}],"isBlockCoverage":true},{"functionName":"signInWithGoogle","ranges":[{"startOffset":1869,"endOffset":2278,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2384,"endOffset":2416,"count":0}],"isBlockCoverage":false},{"functionName":"firebaseSignOut","ranges":[{"startOffset":2445,"endOffset":2486,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2591,"endOffset":2622,"count":0}],"isBlockCoverage":false},{"functionName":"useAuthState","ranges":[{"startOffset":2648,"endOffset":2937,"count":2}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2759,"endOffset":2909,"count":2}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2842,"endOffset":2865,"count":2}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2883,"endOffset":2902,"count":2}],"isBlockCoverage":true},{"functionName":"get","ranges":[{"startOffset":3039,"endOffset":3067,"count":2}],"isBlockCoverage":true},{"functionName":"useDbData","ranges":[{"startOffset":3090,"endOffset":3601,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":3700,"endOffset":3725,"count":0}],"isBlockCoverage":false},{"functionName":"useDbUpdate","ranges":[{"startOffset":3750,"endOffset":4244,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4345,"endOffset":4372,"count":0}],"isBlockCoverage":false},{"functionName":"handleSignIn","ranges":[{"startOffset":4398,"endOffset":4536,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4638,"endOffset":4666,"count":1}],"isBlockCoverage":true},{"functionName":"handleLogout","ranges":[{"startOffset":4692,"endOffset":4715,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4817,"endOffset":4845,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4947,"endOffset":4971,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1364","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/findZipcode.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":6595,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":6595,"count":1}],"isBlockCoverage":true},{"functionName":"getPlaceId","ranges":[{"startOffset":204,"endOffset":776,"count":0}],"isBlockCoverage":false},{"functionName":"getZipCode","ranges":[{"startOffset":797,"endOffset":1441,"count":0}],"isBlockCoverage":false},{"functionName":"getUniversity","ranges":[{"startOffset":1465,"endOffset":1604,"count":0}],"isBlockCoverage":false},{"functionName":"findZipcode","ranges":[{"startOffset":1626,"endOffset":1956,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2057,"endOffset":2084,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1365","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/findCafes.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":4296,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":4296,"count":1}],"isBlockCoverage":true},{"functionName":"findCafes","ranges":[{"startOffset":203,"endOffset":1241,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":1340,"endOffset":1365,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1366","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/ReviewPostPage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":29087,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":29087,"count":1}],"isBlockCoverage":true},{"functionName":"ReviewPostPage","ranges":[{"startOffset":803,"endOffset":13567,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1367","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/ReviewsPage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":5956,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":5956,"count":1}],"isBlockCoverage":true},{"functionName":"ReviewsPage","ranges":[{"startOffset":1083,"endOffset":2687,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1368","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/CafeList.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":5314,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":5314,"count":1}],"isBlockCoverage":true},{"functionName":"CafeList","ranges":[{"startOffset":562,"endOffset":2140,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1369","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/CafeList.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":490,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":490,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1370","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/CafePage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":38549,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":38549,"count":1}],"isBlockCoverage":true},{"functionName":"CafePage","ranges":[{"startOffset":1336,"endOffset":18935,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1371","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/CafePage.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":490,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":490,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1372","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/posts.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":8908,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":8908,"count":1}],"isBlockCoverage":true},{"functionName":"findCafePosts","ranges":[{"startOffset":667,"endOffset":1510,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":1613,"endOffset":1642,"count":0}],"isBlockCoverage":false},{"functionName":"addReplyToPost","ranges":[{"startOffset":1669,"endOffset":2431,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2535,"endOffset":2565,"count":0}],"isBlockCoverage":false},{"functionName":"addCafePost","ranges":[{"startOffset":2589,"endOffset":3161,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":3262,"endOffset":3289,"count":0}],"isBlockCoverage":false}]}]} \ No newline at end of file diff --git a/coverage/.tmp/coverage-1.json b/coverage/.tmp/coverage-1.json new file mode 100644 index 0000000..52b33f1 --- /dev/null +++ b/coverage/.tmp/coverage-1.json @@ -0,0 +1 @@ +{"result":[{"scriptId":"985","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/App.test.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":3719,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":3719,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":771,"endOffset":1388,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":816,"endOffset":1384,"count":1},{"startOffset":1237,"endOffset":1383,"count":0}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1440,"endOffset":1897,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1485,"endOffset":1893,"count":1},{"startOffset":1827,"endOffset":1888,"count":0},{"startOffset":1889,"endOffset":1892,"count":0}],"isBlockCoverage":true}]},{"scriptId":"1251","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/App.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":5369,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":5369,"count":1}],"isBlockCoverage":true},{"functionName":"App","ranges":[{"startOffset":962,"endOffset":3388,"count":2}],"isBlockCoverage":true}]},{"scriptId":"1312","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/LandingPage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":6681,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":6681,"count":1}],"isBlockCoverage":true},{"functionName":"LandingPage","ranges":[{"startOffset":1271,"endOffset":3144,"count":2}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1502,"endOffset":2019,"count":2}],"isBlockCoverage":true},{"functionName":"fetchData","ranges":[{"startOffset":1532,"endOffset":1997,"count":2},{"startOffset":1561,"endOffset":1574,"count":0},{"startOffset":1576,"endOffset":1991,"count":0}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2064,"endOffset":2099,"count":2}],"isBlockCoverage":true}]},{"scriptId":"1314","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/App.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":486,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":486,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1315","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/MapComponent.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":9240,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":9240,"count":1}],"isBlockCoverage":true},{"functionName":"MapComponent","ranges":[{"startOffset":629,"endOffset":3194,"count":2}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":910,"endOffset":1365,"count":2},{"startOffset":943,"endOffset":950,"count":0}],"isBlockCoverage":true},{"functionName":"initMap","ranges":[{"startOffset":971,"endOffset":1345,"count":2},{"startOffset":1054,"endOffset":1344,"count":0}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1406,"endOffset":2896,"count":2},{"startOffset":1427,"endOffset":1443,"count":0},{"startOffset":1452,"endOffset":2895,"count":0}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":1585,"endOffset":2890,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1316","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/Banner.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":14734,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":14734,"count":1}],"isBlockCoverage":true},{"functionName":"Banner","ranges":[{"startOffset":1062,"endOffset":6718,"count":2},{"startOffset":4468,"endOffset":5313,"count":0},{"startOffset":5767,"endOffset":6079,"count":0}],"isBlockCoverage":true},{"functionName":"handleInputChange","ranges":[{"startOffset":1372,"endOffset":1654,"count":0}],"isBlockCoverage":false},{"functionName":"handleSelectCafe","ranges":[{"startOffset":1683,"endOffset":1793,"count":0}],"isBlockCoverage":false},{"functionName":"handleSearch","ranges":[{"startOffset":1818,"endOffset":2188,"count":0}],"isBlockCoverage":false},{"functionName":"","ranges":[{"startOffset":4588,"endOffset":5131,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":6814,"endOffset":6836,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1317","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/Banner.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":490,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":490,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1318","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/Icon.svg","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":555,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":555,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1319","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/Search.svg","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":565,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":565,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1320","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/firebase.js","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":17838,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":17838,"count":1}],"isBlockCoverage":true},{"functionName":"signInWithGoogle","ranges":[{"startOffset":1869,"endOffset":2278,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2384,"endOffset":2416,"count":0}],"isBlockCoverage":false},{"functionName":"firebaseSignOut","ranges":[{"startOffset":2445,"endOffset":2486,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2591,"endOffset":2622,"count":0}],"isBlockCoverage":false},{"functionName":"useAuthState","ranges":[{"startOffset":2648,"endOffset":2937,"count":4}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2759,"endOffset":2909,"count":4}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2842,"endOffset":2865,"count":4}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":2883,"endOffset":2902,"count":4}],"isBlockCoverage":true},{"functionName":"get","ranges":[{"startOffset":3039,"endOffset":3067,"count":4}],"isBlockCoverage":true},{"functionName":"useDbData","ranges":[{"startOffset":3090,"endOffset":3601,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":3700,"endOffset":3725,"count":0}],"isBlockCoverage":false},{"functionName":"useDbUpdate","ranges":[{"startOffset":3750,"endOffset":4244,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4345,"endOffset":4372,"count":0}],"isBlockCoverage":false},{"functionName":"handleSignIn","ranges":[{"startOffset":4398,"endOffset":4536,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4638,"endOffset":4666,"count":2}],"isBlockCoverage":true},{"functionName":"handleLogout","ranges":[{"startOffset":4692,"endOffset":4715,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4817,"endOffset":4845,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":4947,"endOffset":4971,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1364","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/findZipcode.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":6595,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":6595,"count":1}],"isBlockCoverage":true},{"functionName":"getPlaceId","ranges":[{"startOffset":204,"endOffset":776,"count":0}],"isBlockCoverage":false},{"functionName":"getZipCode","ranges":[{"startOffset":797,"endOffset":1441,"count":0}],"isBlockCoverage":false},{"functionName":"getUniversity","ranges":[{"startOffset":1465,"endOffset":1604,"count":0}],"isBlockCoverage":false},{"functionName":"findZipcode","ranges":[{"startOffset":1626,"endOffset":1956,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2057,"endOffset":2084,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1365","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/findCafes.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":4240,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":4240,"count":1}],"isBlockCoverage":true},{"functionName":"findCafes","ranges":[{"startOffset":203,"endOffset":1241,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":1340,"endOffset":1365,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1366","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/ReviewPostPage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":29087,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":29087,"count":1}],"isBlockCoverage":true},{"functionName":"ReviewPostPage","ranges":[{"startOffset":803,"endOffset":13567,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1367","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/ReviewsPage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":5956,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":5956,"count":1}],"isBlockCoverage":true},{"functionName":"ReviewsPage","ranges":[{"startOffset":1083,"endOffset":2687,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1368","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/CafeList.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":5314,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":5314,"count":1}],"isBlockCoverage":true},{"functionName":"CafeList","ranges":[{"startOffset":562,"endOffset":2140,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1369","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/components/CafeList.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":490,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":490,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1370","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/CafePage.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":38549,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":38549,"count":1}],"isBlockCoverage":true},{"functionName":"CafePage","ranges":[{"startOffset":1336,"endOffset":18935,"count":0}],"isBlockCoverage":false}]},{"scriptId":"1371","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/pages/CafePage.css","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":490,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":490,"count":1}],"isBlockCoverage":true}]},{"scriptId":"1372","url":"file:///Users/markfortes/Documents/cs392/CafeWay/src/utilities/posts.jsx","functions":[{"functionName":"","ranges":[{"startOffset":0,"endOffset":8908,"count":1}],"isBlockCoverage":true},{"functionName":"","ranges":[{"startOffset":13,"endOffset":8908,"count":1}],"isBlockCoverage":true},{"functionName":"findCafePosts","ranges":[{"startOffset":667,"endOffset":1510,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":1613,"endOffset":1642,"count":0}],"isBlockCoverage":false},{"functionName":"addReplyToPost","ranges":[{"startOffset":1669,"endOffset":2431,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":2535,"endOffset":2565,"count":0}],"isBlockCoverage":false},{"functionName":"addCafePost","ranges":[{"startOffset":2589,"endOffset":3161,"count":0}],"isBlockCoverage":false},{"functionName":"get","ranges":[{"startOffset":3262,"endOffset":3289,"count":0}],"isBlockCoverage":false}]}]} \ No newline at end of file diff --git a/src/utilities/posts.test.jsx b/src/utilities/posts.test.jsx new file mode 100644 index 0000000..2a6b002 --- /dev/null +++ b/src/utilities/posts.test.jsx @@ -0,0 +1,76 @@ +import { ref, push, set } from 'firebase/database'; +import { addCafePost } from './posts'; +import { vi } from 'vitest'; + +vi.mock('firebase/database', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + ref: vi.fn(), + push: vi.fn(), + set: vi.fn(), + }; +}); + +describe('addCafePost', () => { + const mockCafeId = 'cafe123'; + const mockPost = { + category: 'Review', + content: 'This cafe has great coffee!', + date: '2024-11-16', + email: 'user@example.com', + replies: {}, + }; + + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('should successfully add a cafe post', async () => { + // Mock Firebase functions + const mockPostRef = { key: 'newPost123' }; + vi.mocked(ref).mockReturnValue('mockRef'); + vi.mocked(push).mockReturnValue(mockPostRef); + vi.mocked(set).mockResolvedValueOnce(); + + // Call the function + const result = await addCafePost(mockCafeId, mockPost); + + // Validate calls and behavior + expect(ref).toHaveBeenCalledWith(expect.anything(), '/posts'); + expect(push).toHaveBeenCalledWith('mockRef'); + expect(set).toHaveBeenCalledWith(mockPostRef, { + cafeId: mockCafeId, + category: mockPost.category, + content: mockPost.content, + date: mockPost.date, + email: mockPost.email, + replies: {}, + }); + + // Ensure no errors + expect(result).toBeNull(); + }); + + it('should handle errors when adding a cafe post', async () => { + // Mock Firebase functions to throw an error + const mockError = new Error('Firebase set error'); + vi.mocked(ref).mockReturnValue('mockRef'); + vi.mocked(push).mockReturnValue({ key: 'newPost123' }); + vi.mocked(set).mockRejectedValueOnce(mockError); + + // Spy on console.error + const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); + + // Call the function + const result = await addCafePost(mockCafeId, mockPost); + + // Validate error handling + expect(result).toBe(mockError.message); + expect(consoleErrorSpy).toHaveBeenCalledWith('Error adding cafe post:', mockError); + + // Restore console.error + consoleErrorSpy.mockRestore(); + }); + +}); diff --git a/vite.config.js b/vite.config.js index b312230..ef85eef 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,5 +7,8 @@ export default defineConfig({ test: { globals: true, environment: 'jsdom', + coverage: { + reporter: ['text', 'json', 'html'] + } } });