Created
September 20, 2022 19:22
-
-
Save ejmudrak/76d24b0ba486bad370e6e02cd72338a8 to your computer and use it in GitHub Desktop.
Authentication Helper for testing
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
import assert from 'assert'; | |
import app from './app'; | |
const NOT_AUTHENTICATED_MESSAGE = { | |
name: 'NotAuthenticated', | |
message: 'Not authenticated', | |
}; | |
// Functions for asserting that service methods may not be called when a user is not authenticated | |
export const assertCreateAuthentication = async (service: any) => { | |
return assert.rejects( | |
async () => await app.service(service).create({}, { provider: 'rest' }), | |
NOT_AUTHENTICATED_MESSAGE, | |
); | |
}; | |
export const assertFindAuthentication = async (service: any) => { | |
return assert.rejects( | |
async () => await app.service(service).find({ provider: 'rest' }), | |
NOT_AUTHENTICATED_MESSAGE, | |
); | |
}; | |
export const assertGetAuthentication = async (service: any) => { | |
return assert.rejects( | |
async () => await app.service(service).get(1, { provider: 'rest' }), | |
NOT_AUTHENTICATED_MESSAGE, | |
); | |
}; | |
export const assertPatchAuthentication = async (service: any) => { | |
return assert.rejects( | |
async () => await app.service(service).patch(1, {}, { provider: 'rest' }), | |
NOT_AUTHENTICATED_MESSAGE, | |
); | |
}; | |
export const assertUpdateAuthentication = async (service: any) => { | |
return assert.rejects( | |
async () => await app.service(service).update(1, {}, { provider: 'rest' }), | |
NOT_AUTHENTICATED_MESSAGE, | |
); | |
}; | |
export const assertRemoveAuthentication = async (service: any) => { | |
return assert.rejects( | |
async () => await app.service(service).remove(1, { provider: 'rest' }), | |
NOT_AUTHENTICATED_MESSAGE, | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment