Skip to content

Feature/database-manager : Allow sessions and users to be stored in different databases #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 244 additions & 0 deletions packages/database-manager/__tests__/database-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
import DatabaseManager from '../src';

export default class Database {
public name;

constructor(name) {
this.name = name;
}

public createUser() {
return this.name;
}

public findUserById() {
return this.name;
}

public findUserByEmail() {
return this.name;
}

public findUserByUsername() {
return this.name;
}

public findPasswordHash() {
return this.name;
}

public findUserByEmailVerificationToken() {
return this.name;
}

public findUserByResetPasswordToken() {
return this.name;
}

public findUserByServiceId() {
return this.name;
}

public addEmail() {
return this.name;
}

public removeEmail() {
return this.name;
}

public verifyEmail() {
return this.name;
}

public setUsername() {
return this.name;
}

public setPassword() {
return this.name;
}

public setProfile() {
return this.name;
}

public setService() {
return this.name;
}

public unsetService() {
return this.name;
}

public createSession() {
return this.name;
}

public updateSession() {
return this.name;
}

public invalidateSession() {
return this.name;
}

public invalidateAllSessions() {
return this.name;
}

public findSessionByToken() {
return this.name;
}

public findSessionById() {
return this.name;
}

public addEmailVerificationToken() {
return this.name;
}

public addResetPasswordToken() {
return this.name;
}

public setResetPassword() {
return this.name;
}
}

const databaseManager = new DatabaseManager({
userStorage: new Database('userStorage'),
sessionStorage: new Database('sessionStorage'),
});

describe('DatabaseManager configuration', () => {

it('should throw if no configuration object specified', () => {
expect(() => databaseManager.validateConfiguration()).toThrow();
});

it('should throw if no userStorage specified', () => {
expect(() => databaseManager.validateConfiguration({ sessionStorage: true })).toThrow();
});

it('should throw if no sessionStorage specified', () => {
expect(() => databaseManager.validateConfiguration({ userStorage: true })).toThrow();
});

it('should throw if no sessionStorage specified', () => {
expect(() =>
databaseManager.validateConfiguration({
userStorage: true,
sessionStorage: true,
})
).not.toThrow();
});

});


describe('DatabaseManager', () => {

it('createUser should be called on userStorage', () => {
expect(databaseManager.createUser()).toBe('userStorage');
});

it('findUserById should be called on userStorage', () => {
expect(databaseManager.findUserById()).toBe('userStorage');
});

it('findUserByEmail should be called on userStorage', () => {
expect(databaseManager.findUserByEmail()).toBe('userStorage');
});

it('findUserByUsername should be called on userStorage', () => {
expect(databaseManager.findUserByUsername()).toBe('userStorage');
});

it('findPasswordHash should be called on userStorage', () => {
expect(databaseManager.findPasswordHash()).toBe('userStorage');
});

it('findUserByEmailVerificationToken should be called on userStorage', () => {
expect(databaseManager.findUserByEmailVerificationToken()).toBe('userStorage');
});

it('findUserByResetPasswordToken should be called on userStorage', () => {
expect(databaseManager.findUserByResetPasswordToken()).toBe('userStorage');
});

it('findUserByServiceId should be called on userStorage', () => {
expect(databaseManager.findUserByServiceId()).toBe('userStorage');
});

it('addEmail should be called on userStorage', () => {
expect(databaseManager.addEmail()).toBe('userStorage');
});

it('removeEmail should be called on userStorage', () => {
expect(databaseManager.removeEmail()).toBe('userStorage');
});

it('verifyEmail should be called on userStorage', () => {
expect(databaseManager.verifyEmail()).toBe('userStorage');
});

it('setUsername should be called on userStorage', () => {
expect(databaseManager.setUsername()).toBe('userStorage');
});

it('setPassword should be called on userStorage', () => {
expect(databaseManager.setPassword()).toBe('userStorage');
});

it('setProfile should be called on userStorage', () => {
expect(databaseManager.setProfile()).toBe('userStorage');
});

it('setService should be called on userStorage', () => {
expect(databaseManager.setService()).toBe('userStorage');
});

it('unsetService should be called on userStorage', () => {
expect(databaseManager.unsetService()).toBe('userStorage');
});

it('createSession should be called on sessionStorage', () => {
expect(databaseManager.createSession()).toBe('sessionStorage');
});

it('updateSession should be called on sessionStorage', () => {
expect(databaseManager.updateSession()).toBe('sessionStorage');
});

it('invalidateSession should be called on sessionStorage', () => {
expect(databaseManager.invalidateSession()).toBe('sessionStorage');
});

it('invalidateAllSessions should be called on sessionStorage', () => {
expect(databaseManager.invalidateAllSessions()).toBe('sessionStorage');
});

it('findSessionByToken should be called on sessionStorage', () => {
expect(databaseManager.findSessionByToken()).toBe('sessionStorage');
});

it('findSessionById should be called on sessionStorage', () => {
expect(databaseManager.findSessionById()).toBe('sessionStorage');
});

it('addEmailVerificationToken should be called on sessionStorage', () => {
expect(databaseManager.addEmailVerificationToken()).toBe('userStorage');
});

it('addResetPasswordToken should be called on sessionStorage', () => {
expect(databaseManager.addResetPasswordToken()).toBe('userStorage');
});

it('setResetPassword should be called on sessionStorage', () => {
expect(databaseManager.setResetPassword()).toBe('userStorage');
});

}
7 changes: 7 additions & 0 deletions packages/database-manager/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import DatabaseManager from '../src';

describe('DatabaseManager entry', () => {
it('should have default export DatabaseManager', () => {
expect(typeof DatabaseManager).toBe('function');
});
});
49 changes: 49 additions & 0 deletions packages/database-manager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@accounts/database-manager",
"version": "0.1.0-beta.3",
"description": "Accounts Database Manager, allow the use of separate databases for session and user",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"clean": "rimraf lib",
"start": "tsc --watch",
"precompile": "yarn clean",
"compile": "tsc",
"prepublishOnly": "yarn compile",
"test": "yarn testonly",
"test-ci": "yarn lint && yarn coverage",
"testonly": "jest",
"test:watch": "jest --watch",
"coverage": "yarn testonly -- --coverage"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/../../node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
"moduleFileExtensions": [
"ts",
"js"
]
},
"repository": {
"type": "git",
"url": "https://github.com/accounts-js/accounts/tree/master/packages/database-manager"
},
"keywords": [
"accounts",
"database",
"manager",
"users",
"sessions"
],
"author": "Elies Lou (Aetherall)",
"license": "MIT",
"devDependencies": {
"@accounts/server": "^0.1.0-beta.3",
"rimraf": "2.6.2"
}
}
Loading