This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
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 #580 from Giveth/f_565_fix_create_trace_with_repet…
…itive_title F 565 fix create trace with repetitive title
- Loading branch information
Showing
4 changed files
with
188 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
const { | ||
assertThrowsAsync, | ||
assertNotThrowsAsync, | ||
SAMPLE_DATA, | ||
generateRandomMongoId, | ||
} = require('../../../test/testUtility'); | ||
const { getFeatherAppInstance } = require('../../app'); | ||
|
||
const checkTraceName = require('./checkTraceName'); | ||
|
||
let app; | ||
before(() => { | ||
app = getFeatherAppInstance(); | ||
}); | ||
|
||
const checkTraceNameTestCases = () => { | ||
it('should throw error for repetitive title', async () => { | ||
const traceData = { | ||
...SAMPLE_DATA.createTraceData(), | ||
title: 'test-trace-unique', | ||
ownerAddress: SAMPLE_DATA.USER_ADDRESS, | ||
}; | ||
await app.service('traces').create(traceData); | ||
const context = { | ||
id: generateRandomMongoId(), | ||
app, | ||
data: { | ||
title: traceData.title, | ||
campaignId: traceData.campaignId, | ||
}, | ||
}; | ||
const badFunc = async () => { | ||
await checkTraceName()(context); | ||
}; | ||
await assertThrowsAsync( | ||
badFunc, | ||
'Trace title is repetitive. Please select a different title for the trace.', | ||
); | ||
}); | ||
it('should not throw error for repetitive title but different campaign', async () => { | ||
const traceData = { | ||
...SAMPLE_DATA.createTraceData(), | ||
ownerAddress: SAMPLE_DATA.USER_ADDRESS, | ||
}; | ||
await app.service('traces').create(traceData); | ||
|
||
const context = { | ||
id: generateRandomMongoId(), | ||
app, | ||
data: { | ||
title: traceData.title, | ||
campaignId: generateRandomMongoId(), | ||
}, | ||
}; | ||
const goodFunc = async () => { | ||
await checkTraceName()(context); | ||
}; | ||
await assertNotThrowsAsync(goodFunc); | ||
}); | ||
it('should not throw error for similar title with extra spaces between words', async () => { | ||
const title = 'test repetetive title with space between words'; | ||
const titleWithExtraSpaces = 'test repetetive title with space between words'; | ||
const traceData = { | ||
...SAMPLE_DATA.createTraceData(), | ||
title, | ||
ownerAddress: SAMPLE_DATA.USER_ADDRESS, | ||
}; | ||
await app.service('traces').create(traceData); | ||
|
||
const context = { | ||
id: generateRandomMongoId(), | ||
app, | ||
data: { | ||
title: titleWithExtraSpaces, | ||
campaignId: generateRandomMongoId(), | ||
}, | ||
}; | ||
const goodFunc = async () => { | ||
await checkTraceName()(context); | ||
}; | ||
await assertNotThrowsAsync(goodFunc); | ||
}); | ||
it('should not throw error for similar title with extra spaces at end of title', async () => { | ||
const title = 'test repetetive title with extra spaces at end of title'; | ||
const titleWithExtraSpaces = | ||
'test repetetive title with extra spaces at end of title '; | ||
const traceData = { | ||
...SAMPLE_DATA.createTraceData(), | ||
title, | ||
ownerAddress: SAMPLE_DATA.USER_ADDRESS, | ||
}; | ||
await app.service('traces').create(traceData); | ||
|
||
const context = { | ||
id: generateRandomMongoId(), | ||
app, | ||
data: { | ||
title: titleWithExtraSpaces, | ||
campaignId: generateRandomMongoId(), | ||
}, | ||
}; | ||
const goodFunc = async () => { | ||
await checkTraceName()(context); | ||
}; | ||
await assertNotThrowsAsync(goodFunc); | ||
}); | ||
}; | ||
|
||
describe('test checkTraceName() functions', checkTraceNameTestCases); |
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