mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 05:23:06 +08:00
refactored resolvers, cleaned
This commit is contained in:
@@ -22,6 +22,53 @@ describe('graph.queries.user', () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe('email', () => {
|
||||
const query = `
|
||||
query User($user_id: ID!) {
|
||||
user(id: $user_id) {
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
it('can query for your own email', async () => {
|
||||
const ctx = new Context({ user });
|
||||
|
||||
const { data, errors } = await graphql(schema, query, {}, ctx, {
|
||||
user_id: user.id,
|
||||
});
|
||||
|
||||
expect(errors).to.be.undefined;
|
||||
expect(data.user).to.not.be.null;
|
||||
expect(data.user.email).to.be.equal(user.firstEmail);
|
||||
});
|
||||
|
||||
[
|
||||
{ role: 'COMMENTER', can: false },
|
||||
{ role: 'STAFF', can: false },
|
||||
{ role: 'MODERATOR', can: true },
|
||||
{ role: 'ADMIN', can: true },
|
||||
].forEach(({ role, can }) => {
|
||||
it(`${can ? 'can' : 'can not'} query with role = ${role}`, async () => {
|
||||
const actor = new UserModel({ role });
|
||||
const ctx = new Context({ user: actor });
|
||||
|
||||
const { data, errors } = await graphql(schema, query, {}, ctx, {
|
||||
user_id: user.id,
|
||||
});
|
||||
|
||||
expect(errors).to.be.undefined;
|
||||
if (!can) {
|
||||
expect(data.user).to.be.null;
|
||||
} else {
|
||||
expect(data.user).to.not.be.null;
|
||||
expect(data.user.email).to.be.equal(user.firstEmail);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('state', () => {
|
||||
const meQuery = `
|
||||
query Me {
|
||||
|
||||
Reference in New Issue
Block a user