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

feat: supports cross OS file paths #33

Merged
merged 1 commit into from
Jun 3, 2023
Merged
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
6 changes: 3 additions & 3 deletions src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const {homedir} = require('os');
const sqlite = require('sqlite');
const sqlite3 = require('sqlite3');
const {fileExists} = require('./helpers');
const path = require('path');

/**
* Opens the BurnDownStatus SQLite3 Database
* @param file file name of the SQLite3 DB. If not provided, defaults to ${homedir}/BurnDownStatus.db
* @param file file name of the SQLite3 DB. If not provided, defaults to BurnDownStatus.db in the users home
* @returns SQLite database connection
*/
async function getDBConnection(file) {
const homeDir = homedir();
file = file ? file : `${homeDir}/BurnDownStatus.db`;
file = file ? file : path.join(homedir(),'BurnDownStatus.db');
if (! await fileExists(file)){
console.error(`${file} not found`);
// ! Separation of concerns - this should probably not be doing the exiting, but it is.
Expand Down
5 changes: 3 additions & 2 deletions src/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const sqlite = require('sqlite');
const sqlite3 = require('sqlite3');
const helpers = require('./helpers');
const { getDBConnection } = require('./database');
const path = require('path');

jest.mock('sqlite');
jest.mock('os');
Expand Down Expand Up @@ -32,7 +33,7 @@ describe('database module', () => {
helpers.fileExists.mockReturnValue(true);


const expectedDefaultFile = `${os.homedir()}/BurnDownStatus.db`
const expectedDefaultFile = path.join(os.homedir(),'BurnDownStatus.db')

const file = undefined;
// call function with null file
Expand All @@ -56,7 +57,7 @@ describe('database module', () => {
os.homedir.mockReturnValue(expectedHomeDir);
helpers.fileExists.mockReturnValue(true);

const expectedDefaultFile = `${os.homedir()}/my_database.db`
const expectedDefaultFile = path.join(os.homedir(),'BurnDownStatus.db')

const db = await getDBConnection(expectedDefaultFile)

Expand Down