Skip to content

add account model #23

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

Open
wants to merge 1 commit into
base: feature/bithub-social-refactor
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"dependencies": {
"can-component": "^3.0.0-pre.8",
"can-connect": "^0.6.0-pre.4",
"can-define": "^0.7.4",
"can-define": "^0.7.24",
"can-route": "^3.0.0-pre.5",
"can-route-pushstate": "^3.0.0-pre.3",
"can-stache": "^3.0.0-pre.6",
Expand Down
49 changes: 49 additions & 0 deletions src/models/account-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'steal-mocha';
import chai from 'chai';
import {Account} from './account';

const assert = chai.assert;

describe('models/account', function () {
it('gets all account information', function (done) {
Account.getList().then(function (accounts) {
assert.equal(accounts.length, 1);
assert.equal(accounts[0].email, '[email protected]');
done();
});
});
it('gets specific account information', function (done) {
Account.get({id: 614}).then(function (account) {
assert.equal(account.email, '[email protected]');
done();
});
});
it('creates a new account', function (done) {
const newAccount = new Account({
name: 'name',
email: '[email protected]',
organizations: [{
id: 129,
name: 'Wow Bao'
}]
});
assert.equal(newAccount.email, '[email protected]');
done();
});
it('checks to see if an account has multiple organizations', function (done) {
const newAccount = new Account({
id: 123,
name: 'name',
email: '[email protected]',
organizations: [{
id: 129,
name: 'Wow Bao'
}]
});
assert.equal(newAccount.hasMultipleOrganizations(), false);
Account.get({id: 614}).then(function (account) {
assert.equal(account.hasMultipleOrganizations(), true);
done();
});
});
});
42 changes: 42 additions & 0 deletions src/models/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import DefineMap from 'can-define/map/';
import DefineList from 'can-define/list/';
import superMap from 'can-connect/can/super-map/';
import tag from 'can-connect/can/tag/';

// import Organization from './organization.js';

export const Account = DefineMap.extend({
// properties
id: '*',
organizations: Array,
password: {
value: ''
},
current_password: {
value: ''
},
email: 'string',
name: 'string',

// methods
hasMultipleOrganizations() {
const organizations = this.organizations;
return organizations && organizations.length > 1;
}
});

Account.List = DefineList.extend({
'*': Account
});

export const accountConnection = superMap({
url: '/api/v3/current/account',
idProp: 'id',
Map: Account,
List: Account.List,
name: 'account'
});

tag('account-model', accountConnection);

export default Account;
14 changes: 14 additions & 0 deletions src/models/fixtures/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fixture from 'can-fixture';
import account from './data/current-account.json';

const store = fixture.store([account]);

fixture({
'GET /api/v3/current/account': store.findAll,
'GET /api/v3/current/account/{id}': store.findOne,
'POST /api/v3/current/account': store.create,
'PUT /api/v3/current/account/{id}': store.update,
'DELETE /api/v3/current/account/{id}': store.destroy
});

export default store;
2 changes: 2 additions & 0 deletions src/models/fixtures/fixtures.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// Main file that loads all model fixtures

import 'bithub-admin/models/fixtures/account';
2 changes: 2 additions & 0 deletions src/models/test.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import './fixtures/';

import 'bithub-admin/models/account-test';