chore: 🤖 cleanup json creds code / tests (#1535)
This commit is contained in:
1 parent
f1b7a9cd84
commit
51c1aba794
10 files changed
+117
-81
No files matched your search
@@ -18,6 +18,14 @@ export default class CredentialModel extends GeneratedCredentialModel {
|
||||
return this.id.startsWith('cred');
|
||||
}
|
||||
|
||||
/**
|
||||
* True if type is `json`.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isJSON() {
|
||||
return this.type === 'json';
|
||||
}
|
||||
|
||||
/**
|
||||
* True if credential is an unknown type.
|
||||
* @type {boolean}
|
||||
|
||||
@@ -20,7 +20,9 @@ export default class CredentialSerializer extends ApplicationSerializer {
|
||||
delete serialized.attributes.username;
|
||||
|
||||
if (serialized?.attributes?.json_object) {
|
||||
serialized.attributes.object = JSON.parse(serialized.attributes.json_object);
|
||||
serialized.attributes.object = JSON.parse(
|
||||
serialized.attributes.json_object
|
||||
);
|
||||
delete serialized.attributes.json_object;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,22 @@ module('Unit | Model | credential', function (hooks) {
|
||||
assert.false(modelC.isStatic);
|
||||
});
|
||||
|
||||
test('it has isJSON property and returns the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelA = store.createRecord('credential', { type: 'json' });
|
||||
const modelB = store.createRecord('credential', {
|
||||
type: 'username_password',
|
||||
});
|
||||
const modelC = store.createRecord('credential', {
|
||||
type: 'ssh_private_key',
|
||||
});
|
||||
|
||||
assert.true(modelA.isJSON);
|
||||
assert.false(modelB.isJSON);
|
||||
assert.false(modelC.isJSON);
|
||||
});
|
||||
|
||||
test('it has isUnknown property and returns the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
|
||||
Reference in new issue
Block a user