Skip to content

Commit

Permalink
test: 🧪 add more integration 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 13, 2024
1 parent aa18592 commit c3e2ea1
Show file tree
Hide file tree
Showing 8 changed files with 816 additions and 271 deletions.
2 changes: 2 additions & 0 deletions src/express/auth/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const permissions = shield(
Query: {
// procedures: isLoggedin,
// activityIndex: isLoggedin,
// Procedure
notificationSettings: isLoggedin,
notifiedProcedures: isLoggedin,
// Vote
votes: isLoggedin,
votedProcedures: isVerified,
},
Expand Down
91 changes: 91 additions & 0 deletions src/graphql/resolvers/Activity.integ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,97 @@ import config from '../../config';
const GRAPHQL_API_URL = process.env.GRAPHQL_API_URL || 'http://localhost:3000';

describe('Activity Resolvers', () => {
describe('Queries', () => {
describe('activityIndex', () => {
let procedure: IProcedure;
let user: User;

beforeAll(async () => {
await connectDB(config.DB_URL, { debug: false });

// create tmp procedure
procedure = await ProcedureModel.create({
procedureId: '0000010',
title: 'tmp procedure for activityIndex test',
period: 1,
type: 'Antrag',
voteResults: {
yes: 0,
no: 0,
abstination: 0,
},
});

user = await UserModel.create({
verified: true,
});

// create tmp activities
await ActivityModel.create([
{
procedure,
kind: 'Phone',
actor: user,
},
]);
});

afterAll(async () => {
await Promise.all([
ActivityModel.deleteOne({ procedure: procedure }),
procedure.remove(),
user.remove(),
]);

await disconnectDB();
});

it('fail to get activity index on non-existing procedure', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
query ActivityIndex($procedureId: String!) {
activityIndex(procedureId: $procedureId) {
activityIndex
active
}
}
`,
variables: {
procedureId: 'non-existing-procedure-id',
},
});

const { data } = response.data;

expect(data).toBeDefined();
expect(data.activityIndex).toBeNull();
});

it('get activity index', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
query ActivityIndex($procedureId: String!) {
activityIndex(procedureId: $procedureId) {
activityIndex
active
}
}
`,
variables: {
procedureId: '0000010',
},
});

const { data } = response.data;

expect(data).toBeDefined();
expect(data.activityIndex).toBeDefined();
expect(data.activityIndex.activityIndex).toBe(1);
expect(data.activityIndex.active).toBeTruthy();
});
});
});

describe('Mutations', () => {
describe('increaseActivity', () => {
const DEVICE_HASH = 'SOME_DEVICE_HASH_ACTIVITY_RESOLVER_INCREASE_ACTIVITY';
Expand Down
9 changes: 3 additions & 6 deletions src/graphql/resolvers/ConferenceWeek.integ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ const GRAPHQL_API_URL = process.env.GRAPHQL_API_URL || 'http://localhost:3000';

describe('ConferenceWeek GraphQL API', () => {
it('data with device', async () => {
const response = await axios.post(
GRAPHQL_API_URL,
{
query: `
const response = await axios.post(GRAPHQL_API_URL, {
query: `
query CurrentConferenceWeek {
currentConferenceWeek {
start
Expand All @@ -17,8 +15,7 @@ describe('ConferenceWeek GraphQL API', () => {
}
}
`,
},
);
});

const { data } = response.data;

Expand Down
161 changes: 132 additions & 29 deletions src/graphql/resolvers/Deputy.integ.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
import axios from 'axios';
import { connectDB, disconnectDB } from '../../services/mongoose';
import config from '../../config';
import { DeputyModel, IDeputy } from '@democracy-deutschland/democracy-common';

const GRAPHQL_API_URL = process.env.GRAPHQL_API_URL || 'http://localhost:3000';

describe('Deputy GraphQL API', () => {
it('should return data', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
describe('Queries', () => {
let deputy1: IDeputy;
let deputy2: IDeputy;

beforeAll(async () => {
await connectDB(config.DB_URL, { debug: false });

// create tmp deputies
deputy1 = await DeputyModel.create({
name: 'tmp deputy for deputy test',
party: 'CDU',
webId: '0000010',
constituency: '',
period: 19,
imgURL: 'https://example.com',
});

deputy2 = await DeputyModel.create({
name: 'tmp deputy for deputy test',
party: 'CDU',
webId: '0000011',
constituency: '107',
period: 20,
imgURL: 'https://example.com',
});
});

afterAll(async () => {
await deputy1.remove();
await deputy2.remove();

await disconnectDB();
});

describe('deputies', () => {
it('should return data', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
query Deputies($limit: Int, $offset: Int, $filterTerm: String, $filterConstituency: String, $excludeIds: [String!], $period: Int) {
deputies(
limit: $limit
Expand All @@ -27,27 +65,28 @@ describe('Deputy GraphQL API', () => {
}
}
`,
variables: {
limit: 10,
offset: 0,
filterTerm: '',
filterConstituency: '',
excludeIds: [],
period: 19,
},
});
variables: {
limit: 10,
offset: 0,
filterTerm: '',
filterConstituency: '',
excludeIds: [],
period: 19,
},
});

const { data } = response.data;
const { data } = response.data;

expect(data).toBeDefined();
expect(data.deputies).toBeDefined();
expect(data.deputies.hasMore).toBeDefined();
expect(data.deputies.data).toBeDefined();
});
expect(data).toBeDefined();
expect(data.deputies).toBeDefined();
expect(data.deputies.hasMore).toBeDefined();
expect(data.deputies.data).toBeDefined();
expect(data.deputies.data.length).toBeGreaterThan(0);
});

it('deputies filtered by constituency', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
it('deputies filtered by constituency', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
query GetDeputiesForNewConstituency($filterConstituency: String, $excludeIds: [String!], $period: Int) {
deputies(
filterConstituency: $filterConstituency
Expand All @@ -60,16 +99,80 @@ describe('Deputy GraphQL API', () => {
}
}
`,
variables: {
period: 20,
filterConstituency: '107',
},
variables: {
period: 20,
filterConstituency: '107',
},
});

const { data } = response.data;

expect(data).toBeDefined();
expect(data.deputies).toBeDefined();
expect(data.deputies.data).toBeDefined();
expect(data.deputies.data.length).toBeGreaterThan(0);
});
});

describe('deputyOfConstituency', () => {
it('should return data', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
query DeputiesOfConstituency($constituency: String!, $period: Int) {
deputiesOfConstituency(constituency: $constituency, period: $period) {
_id
name
party
webId
imgURL
constituency
}
}
`,
variables: {
constituency: '107',
period: 20,
},
});

const { data } = response.data;

expect(data).toBeDefined();
expect(data.deputiesOfConstituency).toBeDefined();
expect(data.deputiesOfConstituency.length).toBeGreaterThan(0);
});
});

const { data } = response.data;
describe('deputy', () => {
it('should return data', async () => {
const response = await axios.post(GRAPHQL_API_URL, {
query: `
query Deputy($id: String!) {
deputy(id: $id) {
_id
name
party
webId
imgURL
constituency
}
}
`,
variables: {
id: deputy1.webId,
},
});

const { data } = response.data;

expect(data).toBeDefined();
expect(data.deputies).toBeDefined();
expect(data.deputies.data).toBeDefined();
expect(data).toBeDefined();
expect(data.deputy).toBeDefined();
expect(data.deputy.name).toBe(deputy1.name);
expect(data.deputy.party).toBe(deputy1.party);
expect(data.deputy.webId).toBe(deputy1.webId);
expect(data.deputy.imgURL).toBe(deputy1.imgURL);
expect(data.deputy.constituency).toBe(deputy1.constituency);
});
});
});
});
Loading

0 comments on commit c3e2ea1

Please sign in to comment.