Skip to content

Instantly share code, notes, and snippets.

@ejmudrak
Created September 20, 2022 19:22
Show Gist options
  • Save ejmudrak/76d24b0ba486bad370e6e02cd72338a8 to your computer and use it in GitHub Desktop.
Save ejmudrak/76d24b0ba486bad370e6e02cd72338a8 to your computer and use it in GitHub Desktop.
Authentication Helper for testing
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