generated from imRohan/Typescript-Express-Vuejs-Boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 10
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 #14 from imRohan/refactoring/accountBlocksMgmt
Refactoring how Accounts and Blocks are managed
- Loading branch information
Showing
9 changed files
with
74 additions
and
51 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,14 +60,14 @@ describe('When retrieving an account', () => { | |
name: 'Existing Account', | ||
description: 'Account made while testing', | ||
contactEmail: '[email protected]', | ||
blocks: [], | ||
maxNumberOfBlocks: 50, | ||
notifications: true, | ||
uuid: '6dc70531-d0bf-4b3a-8265-b20f8a69e180', | ||
} | ||
|
||
it ('returns the correct account attributes', async () => { | ||
mockedDataStore.get.mockReturnValueOnce(Promise.resolve(JSON.stringify(_existingAccount))) | ||
mockedDataStore.scan.mockReturnValueOnce(Promise.resolve([])) | ||
|
||
const _accountBase: IAccount = await AccountController.get(_existingAccount.uuid) | ||
expect(_accountBase).toBeDefined() | ||
|
@@ -87,14 +87,25 @@ describe('When deleting an account', () => { | |
name: 'Existing Account', | ||
description: 'Account made while testing', | ||
contactEmail: '[email protected]', | ||
blocks: [], | ||
maxNumberOfBlocks: 50, | ||
notifications: true, | ||
uuid: '6dc70531-d0bf-4b3a-8265-b20f8a69e180', | ||
} | ||
|
||
it ('returns confirmation message', async () => { | ||
mockedDataStore.get.mockReturnValueOnce(Promise.resolve(JSON.stringify(_existingAccount))) | ||
mockedDataStore.scan.mockReturnValueOnce(Promise.resolve([])) | ||
|
||
const _response = await AccountController.delete(_existingAccount.uuid) | ||
expect(_response).toMatch(/Your Pantry has been deleted/) | ||
}) | ||
|
||
it ('deletes all existing blocks', async () => { | ||
mockedDataStore.get | ||
.mockReturnValueOnce(Promise.resolve(JSON.stringify(_existingAccount))) | ||
.mockReturnValueOnce(Promise.resolve(JSON.stringify({ derp: 'flerp' }))) | ||
|
||
mockedDataStore.scan.mockReturnValueOnce(Promise.resolve(['existingBlock'])) | ||
|
||
const _response = await AccountController.delete(_existingAccount.uuid) | ||
expect(_response).toMatch(/Your Pantry has been deleted/) | ||
|
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 |
---|---|---|
|
@@ -12,13 +12,13 @@ const _existingAccount: IAccountPrivate = { | |
name: 'Existing Account', | ||
description: 'Account made while testing', | ||
contactEmail: '[email protected]', | ||
blocks: [], | ||
maxNumberOfBlocks: 50, | ||
notifications: true, | ||
uuid: '6dc70531-d0bf-4b3a-8265-b20f8a69e180', | ||
} | ||
|
||
afterEach(() => { | ||
mockedDataStore.get.mockReset() | ||
jest.clearAllMocks() | ||
}) | ||
|
||
|
@@ -27,24 +27,36 @@ describe('When creating a block', () => { | |
const _accountUUID = '6dc70531-d0bf-4b3a-8265-b20f8a69e180' | ||
|
||
mockedDataStore.get.mockReturnValueOnce(Promise.resolve(JSON.stringify(_existingAccount))) | ||
mockedDataStore.scan.mockReturnValueOnce(Promise.resolve([])) | ||
|
||
const _response = await BlockController.create(_accountUUID, 'NewBlock', { derp: 'flerp' }) | ||
expect(_response).toMatch(/Your Pantry was updated with basket: NewBlock/) | ||
}) | ||
|
||
it ('throws an error if validation fails', async () => { | ||
const _accountUUID = '6dc70531-d0bf-4b3a-8265-b20f8a69e180' | ||
|
||
mockedDataStore.get.mockReturnValueOnce(Promise.resolve(JSON.stringify(_existingAccount))) | ||
mockedDataStore.scan.mockReturnValueOnce(Promise.resolve([])) | ||
|
||
await expect(BlockController.create(_accountUUID, 'NewBlock', {})) | ||
.rejects | ||
.toThrow('Validation failed:') | ||
}) | ||
|
||
it ('throws an error if account has reached max # of blocks', async () => { | ||
const _accountUUID = '6dc70531-d0bf-4b3a-8265-b20f8a69e180' | ||
const _maxedAccount: IAccountPrivate = { | ||
name: 'Maxed Existing Account', | ||
description: 'Account made while testing', | ||
contactEmail: '[email protected]', | ||
blocks: ['blockName'], | ||
maxNumberOfBlocks: 1, | ||
notifications: true, | ||
uuid: '6dc70531-d0bf-4b3a-8265-b20f8a69e180', | ||
} | ||
|
||
mockedDataStore.get.mockReturnValueOnce(Promise.resolve(JSON.stringify(_maxedAccount))) | ||
mockedDataStore.scan.mockReturnValueOnce(Promise.resolve(['oldBlock'])) | ||
|
||
await expect(BlockController.create(_accountUUID, 'NewBlock', { derp: 'flerp' })) | ||
.rejects | ||
|
@@ -98,9 +110,7 @@ describe('When deleting a block', () => { | |
const _accountUUID = '6dc70531-d0bf-4b3a-8265-b20f8a69e180' | ||
const _blockName = 'NewBlock' | ||
|
||
mockedDataStore.get | ||
.mockReturnValueOnce(Promise.resolve(JSON.stringify(_existingAccount))) | ||
.mockReturnValueOnce(Promise.resolve(null)) | ||
mockedDataStore.get.mockReturnValueOnce(Promise.resolve(null)) | ||
|
||
await expect(BlockController.delete(_accountUUID, _blockName)) | ||
.rejects | ||
|