Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 'rename' context-item #971

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add 'rename' to context-handler
  • Loading branch information
fedeci committed Jan 1, 2021
commit a663a4b20f6890aacde4d7e83e3232ed490683b5
8 changes: 8 additions & 0 deletions src/chain/context-handler-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChainCondition, CustomCondition } from '../context-items';
import { check } from '../middlewares/check';
import { Bail } from '../context-items/bail';
import { ContextHandler, ContextHandlerImpl } from './';
import { Rename } from '../context-items/rename';

let builder: ContextBuilder;
let contextHandler: ContextHandler<any>;
Expand Down Expand Up @@ -74,3 +75,10 @@ describe('#optional()', () => {
expect(builder.setOptional).toHaveBeenNthCalledWith(3, false);
});
});

describe('#rename()', () => {
it('adds a Rename item', () => {
contextHandler.rename('foo');
expect(builder.addItem).toHaveBeenCalledWith(new Rename('foo'));
});
});
6 changes: 6 additions & 0 deletions src/chain/context-handler-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Optional } from '../context';
import { ChainCondition, CustomCondition } from '../context-items';
import { CustomValidator } from '../base';
import { Bail } from '../context-items/bail';
import { Rename } from '../context-items/rename';
import { ContextHandler } from './context-handler';
import { ValidationChain } from './validation-chain';

Expand Down Expand Up @@ -37,4 +38,9 @@ export class ContextHandlerImpl<Chain> implements ContextHandler<Chain> {

return this.chain;
}

rename(newPath: string) {
this.builder.addItem(new Rename(newPath));
return this.chain;
}
}
1 change: 1 addition & 0 deletions src/chain/context-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface ContextHandler<Chain> {
bail(): Chain;
if(condition: CustomValidator | ValidationChain): Chain;
optional(options?: Partial<Optional> | true): Chain;
rename(newPath: string): Chain;
}