-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08deb15
commit 52ccc1a
Showing
12 changed files
with
357 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Changelog | ||
|
||
## 1.1.0 (2022-05-XX) | ||
## 1.1.0 (2022-05-16) | ||
|
||
### 🐛 Fixes (1) | ||
|
||
|
@@ -32,14 +32,19 @@ | |
- Remove unused code | ||
- Changed in [PR#19 - Refactor and introduce base history](https://github.com/joachimdalen/azdevops-acceptance-criterias/pull/19) | ||
|
||
### 🚀 Features (1) | ||
### 🚀 Features (2) | ||
|
||
#### `[email protected]` | ||
|
||
- Added processing history | ||
- Added processing history. See [history](https://devops-extensions.dev/docs/extensions/acceptance-criterias/processing/history) | ||
|
||
- Suggested in [GH#3 - Processing history](https://github.com/joachimdalen/azdevops-acceptance-criterias/issues/3) | ||
- Added in [PR#19 - Refactor and introduce base history](https://github.com/joachimdalen/azdevops-acceptance-criterias/pull/19) | ||
|
||
- Added processing comments. See [approvals and rejections](https://devops-extensions.dev/docs/extensions/acceptance-criterias/processing#approvals-and-rejections) | ||
- Suggested in [GH#4 - Approval / Rejection comments](https://github.com/joachimdalen/azdevops-acceptance-criterias/issues/4) | ||
- Added in [PR#21 - Add processing comment](https://github.com/joachimdalen/azdevops-acceptance-criterias/pull/21) | ||
|
||
### 📝 Documentation (1) | ||
|
||
#### `[email protected]` | ||
|
172 changes: 172 additions & 0 deletions
172
src/__tests__/common/services/CriteriaHistoryService.test.ts
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,172 @@ | ||
import { IInternalIdentity } from '@joachimdalen/azdevops-ext-core/CommonTypes'; | ||
|
||
import CriteriaHistoryService from '../../../common/services/CriteriaHistoryService'; | ||
import { StorageService } from '../../../common/services/StorageService'; | ||
import { HistoryDocument, HistoryEvent, ProcessEvent } from '../../../common/types'; | ||
|
||
const identity: IInternalIdentity = { | ||
displayName: 'Test User', | ||
entityId: '1234', | ||
entityType: 'User', | ||
id: '54321', | ||
descriptor: 'user1234', | ||
image: '/image.png' | ||
}; | ||
|
||
const historyWithContent: HistoryDocument = { | ||
__etag: 1, | ||
id: 'AC-1-2', | ||
items: [ | ||
{ | ||
date: new Date(), | ||
event: HistoryEvent.Completed, | ||
actor: identity | ||
} | ||
] | ||
}; | ||
|
||
describe('CriteriaHistoryService', () => { | ||
const getHistorySpy = jest.spyOn(StorageService.prototype, 'getHistory'); | ||
const setHistorySpy = jest.spyOn(StorageService.prototype, 'setHistory'); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
getHistorySpy.mockReset(); | ||
}); | ||
|
||
describe('getProcessEvent', () => { | ||
it('should return approved event without actor', () => { | ||
const service = new CriteriaHistoryService(); | ||
|
||
const evnt = service.getProcessEvent(ProcessEvent.Approve); | ||
expect(evnt.event).toEqual(HistoryEvent.Approved); | ||
expect(evnt.actor).toBeUndefined(); | ||
expect(evnt.properties).toBeUndefined(); | ||
expect(evnt.date).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return rejected event without actor', () => { | ||
const service = new CriteriaHistoryService(); | ||
|
||
const evnt = service.getProcessEvent(ProcessEvent.Reject); | ||
expect(evnt.event).toEqual(HistoryEvent.Rejected); | ||
expect(evnt.actor).toBeUndefined(); | ||
expect(evnt.properties).toBeUndefined(); | ||
expect(evnt.date).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return complete event without actor', () => { | ||
const service = new CriteriaHistoryService(); | ||
|
||
const evnt = service.getProcessEvent(ProcessEvent.Complete); | ||
expect(evnt.event).toEqual(HistoryEvent.Completed); | ||
expect(evnt.actor).toBeUndefined(); | ||
expect(evnt.properties).toBeUndefined(); | ||
expect(evnt.date).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return reset-to-new event without actor', () => { | ||
const service = new CriteriaHistoryService(); | ||
|
||
const evnt = service.getProcessEvent(ProcessEvent.ResetToNew); | ||
expect(evnt.event).toEqual(HistoryEvent.ReOpened); | ||
expect(evnt.actor).toBeUndefined(); | ||
expect(evnt.properties).toBeUndefined(); | ||
expect(evnt.date).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return resubmit-for-approval event without actor', () => { | ||
const service = new CriteriaHistoryService(); | ||
|
||
const evnt = service.getProcessEvent(ProcessEvent.ResubmitForApproval); | ||
expect(evnt.event).toEqual(HistoryEvent.ReApprove); | ||
expect(evnt.actor).toBeUndefined(); | ||
expect(evnt.properties).toBeUndefined(); | ||
expect(evnt.date).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return event with actor', () => { | ||
const service = new CriteriaHistoryService(); | ||
|
||
const evnt = service.getProcessEvent(ProcessEvent.Approve, identity); | ||
expect(evnt.event).toEqual(HistoryEvent.Approved); | ||
expect(evnt.actor).toEqual(identity); | ||
expect(evnt.properties).toBeUndefined(); | ||
expect(evnt.date).not.toBeUndefined(); | ||
}); | ||
it('should return event with actor and comment', () => { | ||
const service = new CriteriaHistoryService(); | ||
|
||
const evnt = service.getProcessEvent(ProcessEvent.Approve, identity, 'Some comment'); | ||
expect(evnt.event).toEqual(HistoryEvent.Approved); | ||
expect(evnt.actor).toEqual(identity); | ||
expect(evnt.properties).not.toBeUndefined(); | ||
expect(evnt.properties?.comment).toEqual('Some comment'); | ||
expect(evnt.date).not.toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('getHistory', () => { | ||
it('should return default when 404 is thrown', async () => { | ||
getHistorySpy.mockRejectedValue({ status: 404 }); | ||
const service = new CriteriaHistoryService(); | ||
|
||
const result = await service.getHistory('AC-1-1'); | ||
|
||
expect(result).not.toBeUndefined(); | ||
expect(result.__etag).toEqual(-1); | ||
expect(result.items.length).toEqual(0); | ||
}); | ||
|
||
it('should return default when fetched is undefined', async () => { | ||
getHistorySpy.mockResolvedValue(undefined); | ||
const service = new CriteriaHistoryService(); | ||
|
||
const result = await service.getHistory('AC-1-1'); | ||
|
||
expect(result).not.toBeUndefined(); | ||
expect(result.__etag).toEqual(-1); | ||
expect(result.items.length).toEqual(0); | ||
}); | ||
|
||
it('should return history', async () => { | ||
getHistorySpy.mockResolvedValue(historyWithContent); | ||
const service = new CriteriaHistoryService(); | ||
|
||
const result = await service.getHistory('AC-1-1'); | ||
|
||
expect(result).not.toBeUndefined(); | ||
expect(result.__etag).toEqual(1); | ||
expect(result.items.length).toEqual(1); | ||
}); | ||
|
||
it('should throw when error is not 404', async () => { | ||
getHistorySpy.mockRejectedValue({ status: 500 }); | ||
const service = new CriteriaHistoryService(); | ||
|
||
expect(async () => await service.getHistory('AC-1-1')).rejects.toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('createOrUpdate', () => { | ||
it('should update item', async () => { | ||
getHistorySpy.mockResolvedValue(historyWithContent); | ||
setHistorySpy.mockImplementation(d => new Promise(resolve => resolve(d))); | ||
|
||
const service = new CriteriaHistoryService(); | ||
|
||
const result = await service.createOrUpdate('AC-1-1', { | ||
date: new Date(), | ||
event: HistoryEvent.Completed, | ||
actor: identity, | ||
properties: { | ||
comment: 'Hello' | ||
} | ||
}); | ||
|
||
expect(result).not.toBeUndefined(); | ||
expect(result.items.length).toEqual(2); | ||
expect(result.items[0].event).toEqual(HistoryEvent.Completed); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.