Skip to content

Commit

Permalink
test: 🧪 add some more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Ruck <[email protected]>
  • Loading branch information
Manuel Ruck committed Jul 14, 2024
1 parent c3e2ea1 commit a41d4ee
Show file tree
Hide file tree
Showing 6 changed files with 610 additions and 162 deletions.
4 changes: 2 additions & 2 deletions src/express/auth/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const isLoggedin = rule({ cache: 'no_cache' })(async (parent, args, { user, devi
logger.graphql('isLoggedin', { user, device });
if (!user || !device) {
logger.warn('Permission denied: You need to login with your Device');
return false;
return Error('Not Authorised!');
}
return true;
});

const isVerified = rule({ cache: 'no_cache' })(async (parent, args, { user, phone }) => {
if (!user || (CONFIG.SMS_VERIFICATION && (!user.isVerified() || !phone))) {
logger.warn('Permission denied: isVerified = false');
return false;
return Error('Not Verified!');
}
return true;
});
Expand Down
49 changes: 48 additions & 1 deletion src/graphql/resolvers/Activity.integ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ describe('Activity Resolvers', () => {
describe('Mutations', () => {
describe('increaseActivity', () => {
const DEVICE_HASH = 'SOME_DEVICE_HASH_ACTIVITY_RESOLVER_INCREASE_ACTIVITY';
let device: Device;
const DEVICE_HASH_NOT_VERIFIED =
'SOME_DEVICE_HASH_ACTIVITY_RESOLVER_INCREASE_ACTIVITY_NOT_VERIFIED';
let deviceNotVerified: Device;
const PHONE_NUMBER = `+49111111111`;
const xPhoneHash = crypto.createHash('sha256').update(PHONE_NUMBER).digest('hex');
const phoneHash = crypto.createHash('sha256').update(xPhoneHash).digest('hex');
let procedure: IProcedure;
let device: Device;
let phone: Phone;
let user: User;
let userNotVerified: User;

beforeAll(async () => {
await connectDB(config.DB_URL, { debug: false });
Expand All @@ -139,10 +143,19 @@ describe('Activity Resolvers', () => {
deviceHash: DEVICE_HASH,
});

deviceNotVerified = await DeviceModel.create({
deviceHash: DEVICE_HASH_NOT_VERIFIED,
});

phone = await PhoneModel.create({
phoneHash,
});

userNotVerified = await UserModel.create({
verified: false,
device: deviceNotVerified,
});

// create tmp user
user = await UserModel.create({
verified: true,
Expand All @@ -158,6 +171,8 @@ describe('Activity Resolvers', () => {
phone.remove(),
device.remove(),
user.remove(),
deviceNotVerified.remove(),
userNotVerified.remove(),
]);

await disconnectDB();
Expand Down Expand Up @@ -226,6 +241,38 @@ describe('Activity Resolvers', () => {
expect(data.increaseActivity.activityIndex).toBeDefined();
expect(data.increaseActivity.active).toBeTruthy();
});

it('not verified', async () => {
const response = await axios.post(
GRAPHQL_API_URL,
{
query: `
mutation IncreaseActivity($procedureId: String!) {
increaseActivity(procedureId: $procedureId) {
activityIndex
active
}
}
`,
variables: {
procedureId: '0000000',
},
},
{
headers: {
'Content-Type': 'application/json',
'x-device-hash': deviceNotVerified.deviceHash,
},
},
);

const { data, errors } = response.data;

expect(data).toBeDefined();
expect(data.increaseActivity).toBeNull();
expect(errors).toBeDefined();
expect(errors[0].message).toBe('Not Verified!');
});
});
});
});
Loading

0 comments on commit a41d4ee

Please sign in to comment.