-
-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathgraphql.connectedAccounts.test.js
68 lines (60 loc) · 2.99 KB
/
graphql.connectedAccounts.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as utils from './utils';
import models from '../server/models';
import { expect } from 'chai';
describe("graphql.connectedAccounts.test.js", () => {
let user, admin, backer, collective, connectedAccount, connectedAccountData;
const editConnectedAccountQuery = `
mutation editConnectedAccount($connectedAccount: ConnectedAccountInputType!) {
editConnectedAccount(connectedAccount: $connectedAccount) {
id
service
settings
}
}
`;
before(() => utils.resetTestDB());
before(async () => {
user = await models.User.createUserWithCollective({ name: "random user" });
backer = await models.User.createUserWithCollective({ name: "backer user" });
admin = await models.User.createUserWithCollective({ name: "admin user" });
collective = await models.Collective.create({ name: "testcollective" });
collective.addUserWithRole(admin, 'ADMIN');
collective.addUserWithRole(backer, 'BACKER');
connectedAccount = await models.ConnectedAccount.create({ CollectiveId: collective.id, service: "twitter", username: "opencollecttest" });
connectedAccountData = {
id: connectedAccount.id,
settings: { tweet: "hello world "}
}
});
describe("failure", () => {
it("fails if not logged in", async () => {
const res = await utils.graphqlQuery(editConnectedAccountQuery, { connectedAccount: connectedAccountData });
expect(res.errors).to.exist;
expect(res.errors[0].message).to.contain("You need to be logged in to edit a connected account");
});
it("fails if connected account not found", async () => {
const res = await utils.graphqlQuery(editConnectedAccountQuery, { connectedAccount: { ...connectedAccountData, id: 100 }}, user);
expect(res.errors).to.exist;
expect(res.errors[0].message).to.contain("Connected account not found");
});
it("fails to update a connected account if not connected as admin of CollectiveId", async () => {
let res;
res = await utils.graphqlQuery(editConnectedAccountQuery, { connectedAccount: connectedAccountData }, user);
expect(res.errors).to.exist;
expect(res.errors[0].message).to.contain("You don't have permission to edit this connected account");
res = await utils.graphqlQuery(editConnectedAccountQuery, { connectedAccount: connectedAccountData }, backer);
expect(res.errors).to.exist;
expect(res.errors[0].message).to.contain("You don't have permission to edit this connected account");
res.errors && console.error(res.errors[0]);
console.log(">>> ", res.data);
})
});
describe("success", () => {
it("successfully updates a connected account", async () => {
const res = await utils.graphqlQuery(editConnectedAccountQuery, { connectedAccount: connectedAccountData }, admin);
expect(res.errors).to.not.exist;
expect(res.data.editConnectedAccount.service).to.equal("twitter");
expect(res.data.editConnectedAccount.settings).to.deep.equal(connectedAccountData.settings);
});
})
})