本文整理汇总了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);
});