-
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.
Merge pull request #33 from blazejkustra/entity-custom-name
Add a decorator to set custom names for entities
- Loading branch information
Showing
11 changed files
with
168 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Dynamode from '@lib/dynamode/index'; | ||
|
||
function customName(newNameEntity: string): ClassDecorator { | ||
return (entity: any) => { | ||
const oldNameEntity = entity.name; | ||
Object.defineProperty(entity, 'name', { | ||
writable: true, | ||
value: newNameEntity, | ||
}); | ||
Dynamode.storage.transferMetadata(oldNameEntity, newNameEntity); | ||
}; | ||
} | ||
|
||
export default customName; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,29 @@ | ||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
|
||
import customName from '@lib/decorators/helpers/customName'; | ||
import Dynamode from '@lib/dynamode/index'; | ||
|
||
describe('Decorators', () => { | ||
let transferMetadataSpy = vi.spyOn(Dynamode.storage, 'transferMetadata'); | ||
|
||
beforeEach(() => { | ||
transferMetadataSpy = vi.spyOn(Dynamode.storage, 'transferMetadata'); | ||
transferMetadataSpy.mockReturnValue(undefined); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
describe('customName', async () => { | ||
test('Should call transfer metadata when renaming an entity', async () => { | ||
customName('NEW_NAME')(class OLD_NAME {}); | ||
expect(transferMetadataSpy).toHaveBeenNthCalledWith(1, 'OLD_NAME', 'NEW_NAME'); | ||
}); | ||
|
||
test('Should call transfer metadata when renaming an entity with the same name', async () => { | ||
customName('OLD_NAME')(class OLD_NAME {}); | ||
expect(transferMetadataSpy).toHaveBeenNthCalledWith(1, 'OLD_NAME', 'OLD_NAME'); | ||
}); | ||
}); | ||
}); |
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