-
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.
- Loading branch information
Manuel Ruck
committed
Jul 13, 2024
1 parent
f344142
commit aa18592
Showing
15 changed files
with
433 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: 🧸 Bearer | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
rule_check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: ⬇️ Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: 🧸 Bearer | ||
uses: bearer/bearer-action@v2 |
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
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,140 @@ | ||
import { | ||
IProcedure, | ||
Device, | ||
Phone, | ||
User, | ||
ProcedureModel, | ||
DeviceModel, | ||
PhoneModel, | ||
UserModel, | ||
ActivityModel, | ||
} from '@democracy-deutschland/democracy-common'; | ||
import axios from 'axios'; | ||
import crypto from 'crypto'; | ||
import { connectDB, disconnectDB } from '../../services/mongoose'; | ||
import config from '../../config'; | ||
|
||
const GRAPHQL_API_URL = process.env.GRAPHQL_API_URL || 'http://localhost:3000'; | ||
|
||
describe('Activity Resolvers', () => { | ||
describe('Mutations', () => { | ||
describe('increaseActivity', () => { | ||
const DEVICE_HASH = 'SOME_DEVICE_HASH_ACTIVITY_RESOLVER_INCREASE_ACTIVITY'; | ||
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; | ||
|
||
beforeAll(async () => { | ||
await connectDB(config.DB_URL, { debug: false }); | ||
|
||
// create tmp procedure | ||
procedure = await ProcedureModel.create({ | ||
procedureId: '0000000', | ||
title: 'tmp procedure for increaseActivity test', | ||
period: 1, | ||
type: 'Antrag', | ||
voteResults: { | ||
yes: 0, | ||
no: 0, | ||
abstination: 0, | ||
}, | ||
}); | ||
|
||
device = await DeviceModel.create({ | ||
deviceHash: DEVICE_HASH, | ||
}); | ||
|
||
phone = await PhoneModel.create({ | ||
phoneHash, | ||
}); | ||
|
||
// create tmp user | ||
user = await UserModel.create({ | ||
verified: true, | ||
device, | ||
phone, | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await Promise.all([ | ||
ActivityModel.deleteOne({ procedure: procedure }), | ||
procedure.remove(), | ||
phone.remove(), | ||
device.remove(), | ||
user.remove(), | ||
]); | ||
|
||
await disconnectDB(); | ||
}); | ||
|
||
it('fail to increase activity on non-existing procedure', async () => { | ||
const response = await axios.post( | ||
GRAPHQL_API_URL, | ||
{ | ||
query: ` | ||
mutation IncreaseActivity($procedureId: String!) { | ||
increaseActivity(procedureId: $procedureId) { | ||
activityIndex | ||
active | ||
} | ||
} | ||
`, | ||
variables: { | ||
procedureId: 'non-existing-procedure-id', | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'x-device-hash': device.deviceHash, | ||
'x-phone-hash': xPhoneHash, | ||
}, | ||
}, | ||
); | ||
|
||
const { data } = response.data; | ||
|
||
expect(data).toBeDefined(); | ||
expect(data.increaseActivity).toBeNull(); | ||
}); | ||
|
||
it('increase activity', 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': device.deviceHash, | ||
'x-phone-hash': xPhoneHash, | ||
}, | ||
}, | ||
); | ||
|
||
const { data } = response.data; | ||
|
||
expect(data).toBeDefined(); | ||
expect(data.increaseActivity).toBeDefined(); | ||
expect(data.increaseActivity.activityIndex).toBeDefined(); | ||
expect(data.increaseActivity.active).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.