本文整理匯總了TypeScript中targaryen.database函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript database函數的具體用法?TypeScript database怎麽用?TypeScript database使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了database函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should be to delete comments as story or comment owner', () => {
const data = {
stories: {
'abc': {
owner: AUTH_STORY_OWNER.uid,
}
},
comments: {
'xyz': {
story: 'abc',
owner: AUTH_COMMENT_OWNER.uid,
},
},
};
const db = targaryen.database(rules, data);
const asCommentOwner = db.as(AUTH_COMMENT_OWNER);
const { allowed: allowedCommentOnwer } = asCommentOwner.write('comments/xyz', {});
expect(allowedCommentOnwer).toBe(true);
const asStoryOwner = db.as(AUTH_STORY_OWNER);
const { allowed: allowedStoryOwner } = asStoryOwner.write('comments/xyz', {});
expect(allowedStoryOwner).toBe(true);
const asHacker = db.as(AUTH_HACKER);
const { allowed: allowedHacker } = asHacker.write('comments/xyz', {});
expect(allowedHacker).toBe(false);
});
示例2: it
it('should be able to edit as the owner', () => {
const data = {
users: {
'123': {
displayName: '.',
}
},
journeys: {
'abc': {
owner: '123',
title: 'đ',
updatedAt: 0,
}
}
};
const db = targaryen.database(rules, data);
const asUser = db.as(AUTH_USER);
const { allowed: allowedUser } = asUser.write('journeys/abc/title', 'đŹ');
expect(allowedUser).toBe(true);
const asHacker = db.as(AUTH_HACKER);
const { allowed: allowedHacker } = asHacker.write('journeys/abc/title', 'HACKED');
expect(allowedHacker).toBe(false);
});
示例3: it
it('should be able to delete as the owner', () => {
const data = {
users: {
'123': {
displayName: '.'
}
},
journeys: {
'abc': {
owner: '123',
}
},
stories: {
'xyz': {
journey: 'abc',
owner: '123',
updatedAt: 0,
title: 'đ'
}
}
};
const db = targaryen.database(rules, data);
const asUser = db.as(AUTH_USER);
const { allowed: allowedUser } = asUser.write('stories/xyz', null);
expect(allowedUser).toBe(true);
const asHacker = db.as(AUTH_HACKER);
const { allowed: allowedHacker } = asHacker.write('stories/xyz', null);
expect(allowedHacker).toBe(false);
});
示例4: it
it('should be able to read a list of users', () => {
const data = {
'123': {
displayName: 'đ',
}
};
const db = targaryen.database(rules, data);
const { allowed } = db.read('users');
expect(allowed).toBe(true);
});
示例5: it
it('should not allow me to write if I\'m not signed in', () => {
const data = {};
const newUserPrivate = {
email: null,
};
const db = targaryen.database(rules, data);
const { allowed } = db.write('usersPrivate/null', newUserPrivate);
expect(allowed).toBe(false);
});