-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
291dddf
commit 07e8f3a
Showing
6 changed files
with
124 additions
and
19 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { PartnerCredentials } from '../../src/1c4a/Partner'; | ||
import { UserCredentials } from '../../src/User'; | ||
|
||
export const partnerCredentials: PartnerCredentials = { | ||
id: 'partnerid', | ||
secret: 'secret', | ||
keyPhase: 2 | ||
}; | ||
|
||
export const userCredentials: UserCredentials = { | ||
username: 'username', | ||
password: 'password' | ||
}; |
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 |
---|---|---|
@@ -1,20 +1,86 @@ | ||
import { expect } from 'chai'; | ||
import moxios from 'moxios'; | ||
import { UserError } from '../../src/Error'; | ||
import { PortokasseService } from '../../src/portokasse/Service'; | ||
import { userStub } from '../stubs/User.stub'; | ||
import { PaymentMethod, PortokasseService } from '../../src/portokasse/Service'; | ||
import { userCredentials } from '../1c4a/helper'; | ||
import { User } from '../../src/User'; | ||
|
||
describe('Portokasse Service', () => { | ||
let service: PortokasseService; | ||
const token = 'bb993a82-8bf8-483d-b5cc-b8cbd1abbd22'; | ||
|
||
beforeEach(() => { | ||
service = new PortokasseService(userStub); | ||
moxios.install(); | ||
moxios.stubOnce('get', /\/login$/, { | ||
status: 200, | ||
headers: { | ||
'set-cookie': [`CSRF-TOKEN=${token}; path=/portokasse; secure`] | ||
}, | ||
response: { email: 'username' } | ||
}); | ||
moxios.stubOnce('post', /\/login$/, { | ||
status: 200, | ||
headers: {}, | ||
response: { email: '[email protected]' } | ||
}); | ||
|
||
service = new PortokasseService(new User()); | ||
}); | ||
|
||
afterEach(() => { | ||
moxios.uninstall(); | ||
}); | ||
|
||
describe('init', () => { | ||
it('should prevent init without user credentials', async () => { | ||
await expect(service.init({} as any)).to.eventually.be.rejectedWith(UserError); | ||
expect(service.init({} as any)).to.eventually.be.rejectedWith(UserError); | ||
expect(service.isInitialized()).to.be.false; | ||
}); | ||
|
||
it('should init with minimal options', async () => { | ||
expect(service.init({ user: userCredentials })).to.eventually.be.fulfilled; | ||
expect(service.isInitialized()).to.be.true; | ||
}); | ||
}); | ||
|
||
it('should access the homepage', () => {}); | ||
describe('getUserInfo', () => { | ||
it('should fail to get user info before init', async () => { | ||
moxios.stubOnce('get', /\/wallet-overviews\/me$/, { | ||
status: 401, | ||
headers: {}, | ||
response: { | ||
code: 'UNAUTHORIZED' | ||
} | ||
}); | ||
|
||
const info = await service.getUserInfo(); | ||
|
||
expect(info.isAuthenticated).to.be.false; | ||
}); | ||
|
||
it('should retrieve user balance', async () => { | ||
moxios.stubOnce('get', /\/wallet-overviews\/me$/, { | ||
status: 200, | ||
headers: {}, | ||
response: { | ||
balance: 2000 | ||
} | ||
}); | ||
|
||
await service.init({ user: userCredentials }); | ||
const info = await service.getUserInfo(); | ||
|
||
expect(info.isAuthenticated).to.be.true; | ||
expect(info.walletBalance).to.exist; | ||
expect(info.walletBalance!.value).to.equal(20); | ||
}); | ||
}); | ||
|
||
describe('topUp', () => { | ||
it('should add tests once topup is implemented', async () => { | ||
const res = await service.topUp(1000, PaymentMethod.GiroPay); | ||
|
||
expect(res).to.be.false; | ||
}); | ||
}); | ||
}); |