Skip to content

Commit

Permalink
JIRA-CHAL-29 #DONE Create a table in the database for voter registrat…
Browse files Browse the repository at this point in the history
…ion data (#21)

* Deleted a provider

* added dataEncryption class and unit tests

* added comments to class code

* fixed small bugs

* fixed PR changes as requested.

* more PR changes as requested

* deleted unused file

* updated comments for decrypt method

* created a new entry for the database. Began to add symlink for the database migration and test file

* created symlink for 20240711063356_initial_schema.sql

* added comments and formated code

* Created a script to copy the migration file into the test directory

* Made pr changes, fixed symlink script bug

* Added the sql file to the test folder

* run copy-migration-to-test-folder script before supabase script

* changed paths of scripts to get the checks to pass in github

* running the copy migration file during the test:ci

* changed scripts so that it doesnt just copy the file. It now does the entire directory

* added the idNumber field to table

* PR review changes

* added state field to the database table

* changed state_ -> us_state
  • Loading branch information
IshanBhatBhardwaj committed Aug 9, 2024
1 parent 3a45eb9 commit 30abec2
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 126 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ jobs:
with:
version: latest
- run: npm ci
- run: npm run copy-migration-to-test-folder
- run: npm run supabase-test:start
- run: npm run test:ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.pnp
.pnp.js
.yarn/install-state.gz
src/__tests__/supabase/migrations/


# testing
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Replace the values of the variables inside .env with appropriate entries. Values
Values for Supabase variables will be displayed in the terminal after running either `npm run supabase-dev:start` or `npm run supabase-test:start`. These values will be
the same for both commands, and will be the same each time you run these commands.

Run the script 'npm run create-symlink-supabase-to-src'. This will create a symlink between the supabase/migrations/20240711063356_initial_schema.sql file -> src/__tests__/supabase/migrations/20240711063356_initial_schema.sql file.
Note, if you are a windows user, you may have to run the command prompt as an administrator to run the script.
=======
## Selenium Tests

### Prerequisites
Expand Down Expand Up @@ -132,8 +135,6 @@ npm run start
To run the Selenium tests, navigate into `src/__tests__/e2e` and run
`python3 -m pytest`.



## Contributing

New engineers should review [CONTRIBUTING.md](https://github.com/8by8-org/8by8-challenge/blob/development/CONTRIBUTING.md) for details about the recommended workflow and tools.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"lint": "next lint",
"format": "prettier --write \"**/*.+(js|ts|tsx|json)\"",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
"build-storybook": "storybook build",
"create-symlink-supabase-to-src": "node scripts/create-symlink-supabase-to-src.js",
"copy-migration-to-test-folder": "node scripts/copy-migration-to-test-folder.js"
},
"dependencies": {
"@paralleldrive/cuid2": "^2.2.2",
Expand Down
19 changes: 19 additions & 0 deletions scripts/copy-migration-to-test-folder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* copies file from @/supabase/migrations/20240711063356_initial_schema.sql --> src/__tests__/supabase/migrations/20240711063356_initial_schema.sql
*/
const fs = require('fs-extra');
const path = require('path');

let sourcePath = path.join(__dirname, '../supabase/migrations');
let destPath = path.join(__dirname, '../src/__tests__/supabase/migrations');

async function copyDirectory() {
try {
await fs.copy(sourcePath, destPath);
console.log('Directory copied successfully!');
} catch (err) {
console.error('Error copying directory:', err);
}
}

copyDirectory();
45 changes: 45 additions & 0 deletions scripts/create-symlink-supabase-to-src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require('fs');
const path = require('path');

// Define the paths to the directories
const databaseDirPath = path.join(__dirname, '../supabase/migrations');
const testDirPath = path.join(
__dirname,
'../src/__tests__/supabase/migrations',
);

// Function to create a symbolic link
function createSymlink(source, destination) {
fs.stat(destination, (err, stats) => {
if (!err) {
console.log(`Existing file or symlink at ${destination}:`);
console.log(`- Is a symlink: ${stats.isSymbolicLink()}`);
console.log(`- Is a file: ${stats.isFile()}`);
console.log(`- Is a directory: ${stats.isDirectory()}`);
console.log(`- Size: ${stats.size} bytes`);
console.log(`- Last modified: ${stats.mtime}\n`);

if (stats.isSymbolicLink() || stats.isDirectory()) {
console.error(
'Symlink or Directory already exists. Please remove before running this script.',
);
} else {
console.error(
`Error: ${destination} exists but is not a directory or symlink.\n`,
);
}
} else if (err.code === 'ENOENT') {
fs.symlink(source, destination, 'dir', symlinkErr => {
if (symlinkErr) {
console.error(`Error creating symlink: ${symlinkErr.message}\n`);
} else {
console.log(`Symlink created: ${destination} -> ${source}\n`);
}
});
} else {
console.error(`Error checking destination: ${err.message}\n`);
}
});
}

createSymlink(databaseDirPath, testDirPath);
122 changes: 0 additions & 122 deletions src/__tests__/supabase/migrations/20240711063356_initial_schema.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const WebCryptoSubtleEncryptor = inject(
* @encryptData
* @param data - string to encrypt
* @param key - a cryptoKey for encryption and decryption
* @returns A string with the initialization vector concatenated with the encrypted data
* @returns A string with the initialization vector concatenated with the encrypted data. The return value will have length of 12 (length of iv) + X (length of plaintext to encrypt) + 16 (authentication tag)
*/
async encrypt(data: string, key: CryptoKey): Promise<string> {
const encoder = new TextEncoder();
Expand Down
25 changes: 25 additions & 0 deletions supabase/migrations/20240711063356_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ create policy "Users can view their own contributed to data."
on public.contributed_to for select
using ((select auth.uid()) = player_id);

-- Create registration_information table, enable row level security, and set a policy
create table public.registration_information (
id serial,
user_id uuid not null references public.users on delete cascade,
us_state varchar(255) not null,
city varchar(255) not null,
street varchar(255) not null,
name_first varchar(255) not null,
name_last varchar(255) not null,
dob varchar(255) not null,
zip varchar(255) not null,
email varchar(255) not null,
citizen varchar(255) not null,
eighteenPlus varchar(255) not null,
party varchar(255) not null,
idNumber varchar(255) not null,
primary key (id, user_id)
);

alter table public.registration_information enable row level security;

create policy "Users can view their own registration information."
on public.registration_information for select
using ((select auth.uid()) = user_id);

-- Create a function that creates new rows in public.users and public.completed_actions
create function public.handle_new_user()
returns trigger
Expand Down

0 comments on commit 30abec2

Please sign in to comment.