Skip to content

Commit

Permalink
Merge pull request #139 from SCCapstone/divine-testing-final
Browse files Browse the repository at this point in the history
Divine testing final
  • Loading branch information
colelewis authored Apr 22, 2022
2 parents 60c169d + e0ae645 commit ad7cf1e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
14 changes: 14 additions & 0 deletions firebaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export async function pushUsernameToDatabase (username) {
})
}

export async function removeUsernameFromDatabase (username) {
await updateDoc(usernameRef, {
usernames: arrayRemove(username)
})
}

export async function pushAccountToDatabase (u) {
await setDoc(doc(database, 'accounts', u.MiD), {
MID: u.MiD,
Expand Down Expand Up @@ -147,6 +153,14 @@ export async function alterPostScore (u, postID, change) { // increment/decremen
// Post component handles interaction
}

export async function alterPostScoreClean (postID, change) {
const postRef = doc(database, 'posts', postID)
await updateDoc(doc(database, 'posts', postID), {
score: increment(change)
})
// Post component handles interaction
}

export async function addUserInteraction (u, postID, change) {
let actionTaken = ''
if (change > 0) {
Expand Down
26 changes: 26 additions & 0 deletions test/unit/post.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Post} from '../../Post'
import { alterPostScoreClean, doesPostExist, getScoreFromPostInDatabase, pushPostToDatabase, removePostFromDatabase } from '../../firebaseConfig'

test('Create post and push to database.', async () => {
var p1 = new Post("meso-229a6114ef7", "p1", null, "p1 -- test", 0, [], new Date().toString().substring(0, 24));
await pushPostToDatabase(p1)
const result = await doesPostExist('p1')
expect(result).toBe(true)
});

test ('Increment post score by 1.', async () => {
await alterPostScoreClean('p1', 1)
const p1_score_1 = await getScoreFromPostInDatabase('p1')
expect(p1_score_1).toBe(1)
await alterPostScoreClean('p1', -1)
})

test ('Decrement post score by 1.', async () => {
await alterPostScoreClean('p1', -1)
const p1_score_1 = await getScoreFromPostInDatabase('p1')
expect(p1_score_1).toBe(-1)
await alterPostScoreClean('p1', 1) // put back to zero
})



32 changes: 11 additions & 21 deletions test/unit/user.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { checkLogin, getUsername, deleteCurrUser, makeAcc, makeAdminAcc, makeDemoAcc } from '../../User'
import { getData, setUser, getUser } from '../../Utility'
import pushAccountToDatabase, { doesAccountExist, doesUsernameExist, removeAccountFromDatabase } from '../../firebaseConfig'
import pushAccountToDatabase, { doesAccountExist, doesUsernameExist, pushUsernameToDatabase, removeAccountFromDatabase, removeUsernameFromDatabase } from '../../firebaseConfig'
import { atom } from 'elementos'

const currUser$ = atom(null)

//Tests of database reading - using Kevin's acc as a base
test('App reads data from the database', async () => {
Expand All @@ -23,26 +26,13 @@ test('App reads account data - but false', async () => {
expect(data).toBe(false)
});

test('Push User Name to DB', async () => {
const data0 = await doesUsernameExist('someUserName!')
expect(data0).toBe(false)

test('App reads account data - but false', async () => {
await makeAcc('someUsernameNotThereYet', '1234', 'No Names', 'bio')
const u = getUser()
console.log(u)
const data1 = await doesUsernameExist('someUsernameNotThereYet')
expect(data1).toBe(true)
//removeAccountFromDatabase(u)
});

await pushUsernameToDatabase('someUserName!')
const data = await doesUsernameExist('someUserName!')

//Validation Checks
test('Username Validation Check', async () => {
makeAcc('no', '1234', 'No Names', 'bio')
const data1 = await doesUsernameExist('no')
expect(data1).toBe(false)
});

test('Display Name Validation Check', async () => {
makeAcc('actual', '1234', 'No', 'bio')
const data1 = await doesUsernameExist('actual')
expect(data1).toBe(false)
expect(data).toBe(true)
await removeUsernameFromDatabase('someUserName!')
});

0 comments on commit ad7cf1e

Please sign in to comment.