Skip to content

Commit

Permalink
adds additional unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan committed May 28, 2024
1 parent 6c2fa13 commit c0cccc2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,44 @@ describe('Pouchdb Session authentication plugin', () => {
]);
});

it('should allow for different sessions per server', async () => {
const db1 = { name: 'http://localhost:5984/db1', session: 'session1'};
const db2 = { name: 'http://localhost:5984/db2', session: 'session2' };
plugin(PouchDb);
PouchDb.adapters.http(db1);
PouchDb.adapters.http(db2);

fetch.resolves({ ok: true, status: 200 });

await db1.fetch('http://localhost:5984/db1');
await db2.fetch('http://localhost:5984/db2');

expect(fetch.callCount).to.equal(2);
expect(fetch.args[0]).to.deep.equal([
'http://localhost:5984/db1',
{ headers: new Headers({ 'Cookie': 'AuthSession=session1' }) }
]);

expect(fetch.args[1]).to.deep.equal([
'http://localhost:5984/db2',
{ headers: new Headers({ 'Cookie': 'AuthSession=session2' }) }
]);

await db1.fetch('http://localhost:5984/db1/_all_docs');
await db2.fetch('http://localhost:5984/db2/_all_docs');

expect(fetch.callCount).to.equal(4);

expect(fetch.args[2]).to.deep.equal([
'http://localhost:5984/db1/_all_docs',
{ headers: new Headers({ 'Cookie': 'AuthSession=session1' }) }
]);
expect(fetch.args[3]).to.deep.equal([
'http://localhost:5984/db2/_all_docs',
{ headers: new Headers({ 'Cookie': 'AuthSession=session2' }) }
]);
});

it('should only request session once for concurrent requests', async () => {
db = { name: 'http://admin:pass@localhost:5984/mydb' };
plugin(PouchDb);
Expand Down

0 comments on commit c0cccc2

Please sign in to comment.