-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5970 from reactioncommerce/chore-integration-test…
…-updateGlobalSettings adds integration test updateGlobalSettings mutation
- Loading branch information
Showing
8 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ration/api/mutations/updateGlobalSettings/__snapshots__/updateGlobalSettings.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`an anonymous user cannot update global settings 1`] = ` | ||
Array [ | ||
Object { | ||
"extensions": Object { | ||
"code": "FORBIDDEN", | ||
"exception": Object { | ||
"details": Object {}, | ||
"error": "access-denied", | ||
"eventData": Object {}, | ||
"isClientSafe": true, | ||
"reason": "Access Denied", | ||
}, | ||
}, | ||
"locations": Array [ | ||
Object { | ||
"column": 3, | ||
"line": 2, | ||
}, | ||
], | ||
"message": "Access Denied", | ||
"path": Array [ | ||
"updateGlobalSettings", | ||
], | ||
}, | ||
] | ||
`; |
7 changes: 7 additions & 0 deletions
7
tests/integration/api/mutations/updateGlobalSettings/updateGlobalSettings.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mutation updateGlobalSettings($input: UpdateGlobalSettingsInput!) { | ||
updateGlobalSettings(input: $input) { | ||
globalSettings { | ||
canSellDigitalProducts | ||
} | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
tests/integration/api/mutations/updateGlobalSettings/updateGlobalSettings.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import importAsString from "@reactioncommerce/api-utils/importAsString.js"; | ||
import Factory from "/tests/util/factory.js"; | ||
import TestApp from "/tests/util/TestApp.js"; | ||
|
||
const updateGlobalSettings = importAsString("./updateGlobalSettings.graphql"); | ||
const TestGlobalSettingSchema = ` | ||
extend type GlobalSettings { | ||
canSellDigitalProducts: Boolean | ||
} | ||
extend input GlobalSettingsUpdates { | ||
canSellDigitalProducts: Boolean | ||
} | ||
extend input UpdateGlobalSettingsInput { | ||
""" | ||
If true a shop can sell digital products | ||
""" | ||
canSellDigitalProducts: Boolean | ||
} | ||
`; | ||
|
||
jest.setTimeout(300000); | ||
|
||
const shopId = "123"; | ||
const shopName = "Test Shop"; | ||
let testApp; | ||
let globalSettingsMutation; | ||
|
||
const mockGlobalSetting = { | ||
canSellDigitalProducts: false | ||
}; | ||
|
||
const mockAdminAccount = Factory.Account.makeOne({ | ||
roles: { | ||
__global_roles__: ["admin"] // eslint-disable-line camelcase | ||
} | ||
}); | ||
|
||
beforeAll(async () => { | ||
testApp = new TestApp(); | ||
|
||
testApp.registerPlugin({ | ||
name: "testGlobalSetting", | ||
graphQL: { | ||
schemas: [TestGlobalSettingSchema] | ||
}, | ||
globalSettingsConfig: { | ||
canSellDigitalProducts: { | ||
rolesThatCanEdit: ["admin"], | ||
simpleSchema: { | ||
type: Boolean | ||
} | ||
} | ||
} | ||
}); | ||
|
||
await testApp.start(); | ||
await testApp.insertPrimaryShop({ _id: shopId, name: shopName }); | ||
await testApp.createUserAndAccount(mockAdminAccount); | ||
await testApp.collections.AppSettings.insertOne(mockGlobalSetting); | ||
globalSettingsMutation = testApp.query(updateGlobalSettings); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testApp.collections.AppSettings.deleteMany({}); | ||
await testApp.collections.Shops.deleteMany({}); | ||
await testApp.stop(); | ||
}); | ||
|
||
test("an anonymous user cannot update global settings", async () => { | ||
try { | ||
await globalSettingsMutation({ | ||
input: { | ||
settingsUpdates: { | ||
canSellDigitalProducts: true | ||
} | ||
} | ||
}); | ||
} catch (error) { | ||
expect(error).toMatchSnapshot(); | ||
} | ||
}); | ||
|
||
test("an admin user can update global settings", async () => { | ||
let result; | ||
await testApp.setLoggedInUser(mockAdminAccount); | ||
const settings = await testApp.collections.AppSettings.findOne({ | ||
canSellDigitalProducts: false | ||
}); | ||
expect(settings.canSellDigitalProducts).toEqual(false); | ||
|
||
try { | ||
result = await globalSettingsMutation({ | ||
input: { | ||
settingsUpdates: { | ||
canSellDigitalProducts: true | ||
} | ||
} | ||
}); | ||
} catch (error) { | ||
expect(error).toBeUndefined(); | ||
return; | ||
} | ||
|
||
expect(result.updateGlobalSettings.globalSettings.canSellDigitalProducts).toEqual(true); | ||
}); |
3 changes: 0 additions & 3 deletions
3
tests/integration/api/queries/globalSettings/TestGlobalSettingSchema.graphql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters