chore: 🤖 make proxy fields first-class attributes on session

This commit is contained in:
Randall Morey committed 2021-02-03 14:29:13 -05:00
1 parent 354d4fd5a6
commit 6ddaa1fedc
4 files changed
+48 -9

No files matched your search

+15
View File
@@ -1,10 +1,14 @@
import GeneratedSessionModel from '../generated/models/session';
import { computed } from '@ember/object';
import { attr } from '@ember-data/model';
export default class SessionModel extends GeneratedSessionModel {
// =attributes
@attr('string', { readOnly: true }) proxy_address;
@attr('number', { readOnly: true }) proxy_port;
/**
* @type {boolean}
*/
@@ -13,6 +17,17 @@ export default class SessionModel extends GeneratedSessionModel {
return this.status?.match(/(active)|(pending)/i);
}
/**
* The full proxy address and port if address exists, otherwise null.
* @type {?string}
*/
@computed('proxy_address', 'proxy_port')
get proxy() {
return this.proxy_address
? `${this.proxy_address}:${this.proxy_port}`
: null;
}
// =methods
/**
@@ -26,4 +26,15 @@ module('Unit | Model | session', function(hooks) {
});
assert.ok(model.isCancelable);
});
test('it computes a proxy attribute', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('session');
assert.equal(model.proxy, null);
model.setProperties({
proxy_address: 'localhost',
proxy_port: '12345'
});
assert.equal(model.proxy, 'localhost:12345');
});
});