-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from devsoc-unsw/features/society-dropdown
Features/society dropdown
- Loading branch information
Showing
19 changed files
with
715 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { StorageClient } from '@supabase/storage-js'; | ||
import { decode } from 'base64-arraybuffer'; | ||
|
||
const STORAGE_URL = process.env['STORAGE_URL']; | ||
const SERVICE_KEY = process.env['SERVICE_ROLE']; | ||
|
||
if (process.env['NODE_ENV'] !== 'test' && !STORAGE_URL) { | ||
throw new Error('Storage URL not found.'); | ||
} | ||
if (process.env['NODE_ENV'] !== 'test' && !SERVICE_KEY) { | ||
throw new Error('Service key not found.'); | ||
} | ||
|
||
export let storageClient: StorageClient | null = null; | ||
if (STORAGE_URL && SERVICE_KEY) { | ||
storageClient = new StorageClient(STORAGE_URL, { | ||
apikey: SERVICE_KEY, | ||
Authorization: `Bearer ${SERVICE_KEY}`, | ||
}); | ||
} | ||
|
||
export const uploadFile = async ( | ||
file: string, | ||
fileType: string, | ||
societyId: number, | ||
eventName: string | ||
) => { | ||
if (!storageClient) { | ||
throw new Error('Storage client not initialised.'); | ||
} | ||
const { data, error } = await storageClient | ||
.from('images') | ||
.upload( | ||
`${societyId}/${eventName}/banner.${fileType.split('/')[1]}`, | ||
decode(file), | ||
{ | ||
contentType: fileType, | ||
upsert: true, | ||
} | ||
); | ||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
console.log(data); | ||
return data.path; | ||
}; | ||
|
||
export const getFile = async (path: string) => { | ||
if (!storageClient) { | ||
throw new Error('Storage client not initialised.'); | ||
} | ||
const { data, error } = await storageClient.from('images').download(path); | ||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
|
||
return data; | ||
}; | ||
|
||
export const getFileUrl = async (path: string) => { | ||
if (!storageClient) { | ||
throw new Error('Storage client not initialised.'); | ||
} | ||
|
||
const { data } = await storageClient.from('images').getPublicUrl(path); | ||
|
||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import app from '../src/index'; | |
import { createClient } from 'redis'; | ||
import prisma from '../src/prisma'; | ||
|
||
describe.skip('Password change', () => { | ||
describe('Password change', () => { | ||
test('Forgot password OTP', async () => { | ||
const redisClient = createClient({ | ||
url: `redis://localhost:${process.env['REDIS_PORT']}`, | ||
|
@@ -45,6 +45,7 @@ describe.skip('Password change', () => { | |
const expToken = await redisClient.get(newUser.email); | ||
|
||
expect(expToken).not.toBeNull(); | ||
|
||
expect(expToken).toEqual(expResToken); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
@@ -106,14 +107,11 @@ describe.skip('Password change', () => { | |
const forgotRes = await request(app).post('/auth/password/forgot').send({ | ||
email: '[email protected]', | ||
token: fResToken, | ||
newPassword: 'oraclefan1', | ||
password: 'oraclefan1', | ||
}); | ||
|
||
//console.log(forgotRes.error.text); | ||
expect(forgotRes.status).toBe(200); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
const fCheckVerTokens = await redisClient.get(newUser.email); | ||
expect(fCheckVerTokens).toBeNull(); | ||
|
||
|
@@ -194,7 +192,7 @@ describe.skip('Password change', () => { | |
username: 'richard grayson', | ||
password: 'iheartkori', | ||
}); | ||
expect(updateResFail.status).toBe(400); | ||
expect(oldPassResFail.status).toBe(400); | ||
|
||
const newPassRes = await request(app).post('/auth/login').send({ | ||
username: 'richard grayson', | ||
|
Oops, something went wrong.