fixes from review

This commit is contained in:
Shelley Vohr 2017-12-11 18:20:12 -05:00
parent 027e78639a
commit a8e67e7f61
No known key found for this signature in database
GPG key ID: F13993A75599653C
2 changed files with 15 additions and 26 deletions

View file

@ -150,7 +150,6 @@ void SystemPreferences::RegisterDefaults(mate::Arguments* args) {
if(!args->GetNext(&value)) {
args->ThrowError("Invalid userDefault data provided");
} else {
args->GetNext(&value);
@try {
NSDictionary* dict = DictionaryValueToNSDictionary(value);
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];

View file

@ -41,45 +41,35 @@ describe('systemPreferences module', () => {
})
it('registers defaults', () => {
// to pass into registerDefaults
const defaultsDict = {
'one': 'ONE',
'two': 2,
'three': [1, 2, 3]
}
// to test type
const defaultsMap = [
{ key: 'one', type: 'string', value: 'ONE' },
{ key: 'two', value: 2, type: 'integer' },
{ key: 'three', value: [1, 2, 3], type: 'array' }
]
const defaultsDict = {}
defaultsMap.forEach(row => { defaultsDict[row.key] = row.value })
systemPreferences.registerDefaults(defaultsDict)
for (const def of defaultsMap) {
const [key, expectedValue, type] = [def.key, def.value, def.type]
for (const userDefault of defaultsMap) {
const { key, value: expectedValue, type } = userDefault
const actualValue = systemPreferences.getUserDefault(key, type)
assert.deepEqual(actualValue, expectedValue)
}
})
it('throws when bad defaults are passed', () => {
const badDefaults1 = { 'one': null } // catches null values
const badDefaults2 = 1 // argument must be a dictionary
const badDefaults3 = null // argument can't be null
assert.throws(() => {
systemPreferences.registerDefaults(badDefaults1)
}, 'Invalid userDefault data provided')
assert.throws(() => {
systemPreferences.registerDefaults(badDefaults2)
}, 'Invalid userDefault data provided')
assert.throws(() => {
systemPreferences.registerDefaults(badDefaults3)
}, 'Invalid userDefault data provided')
for (const badDefaults of [
{ 'one': null }, // catches null values
1, // argument must be a dictionary
null, // argument can't be null
new Date() // shouldn't be able to pass date object
]) {
assert.throws(() => {
systemPreferences.registerDefaults(badDefaults)
}, 'Invalid userDefault data provided')
}
})
})