Skip to content

Commit

Permalink
fix: resolved an issue with target prefixes not being respected
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-sanare committed Aug 12, 2023
1 parent 39c2fb3 commit af7cbdd
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .docs/extending/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { KeyInfo, SourceModule } from '@refreshly/core';
export class MyServiceSourceModule extends SourceModule {
private options: Omit<MyServiceSourceModule.Options, keyof SourceModule.Options>;

constructor({ targets, ...options }: SourceModule.Options) {
super({ targets });
constructor({ targets, prefix, ...options }: SourceModule.Options) {
super({ targets, prefix });

this.options = options;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/aws/src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export class AWSSourceModule extends SourceModule {

private accessKey?: AccessKey;

constructor({ targets, key, secretKey, ...options }: AWSSourceModule.Options) {
super({ targets });
constructor({ targets, prefix, key, secretKey, ...options }: AWSSourceModule.Options) {
super({ targets, prefix });

this.options = {
...options,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/dotenv/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export class DotEnvSourceModule extends SourceModule {
private options: Omit<DotEnvSourceModule.Options, keyof SourceModule.Options>;
private keyInfos: KeyInfo[];

constructor({ targets, file, ...options }: DotEnvSourceModule.Options) {
super({ targets });
constructor({ targets, prefix, file, ...options }: DotEnvSourceModule.Options) {
super({ targets, prefix });

this.options = {
...options,
Expand Down
60 changes: 60 additions & 0 deletions packages/core/src/modules/__tests__/source.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { SourceModule } from '..';
import { KeyInfo } from '../..';

describe('SourceModule', () => {
describe('func(prefix)', () => {
class FakeModule extends SourceModule {
get name(): string {
throw new Error('Method not implemented.');
}

get originalKeyInfos(): KeyInfo[] {
throw new Error('Method not implemented.');
}

source(): Promise<KeyInfo[]> {
throw new Error('Method not implemented.');
}
}

it('should apply the prefix', async () => {
const module = new FakeModule({
prefix: 'CI_ONLY_',
targets: [],
});

const keyInfos: Promise<KeyInfo[]> = Promise.resolve([
{
name: 'HELLO',
value: 'WORLD',
},
]);

await expect(module.prefix(keyInfos)).resolves.toEqual([
{
name: 'CI_ONLY_HELLO',
value: 'WORLD',
},
]);
});

it('should return the original KeyInfos if no prefix is defined', async () => {
const module = new FakeModule({
targets: [],
});
const keyInfos: Promise<KeyInfo[]> = Promise.resolve([
{
name: 'HELLO',
value: 'WORLD',
},
]);

await expect(module.prefix(keyInfos)).resolves.toEqual([
{
name: 'HELLO',
value: 'WORLD',
},
]);
});
});
});
53 changes: 53 additions & 0 deletions packages/core/src/modules/__tests__/target.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { TargetModule } from '..';

describe('TargetModule', () => {
describe('func(prefix)', () => {
class FakeModule extends TargetModule {
get name(): string {
throw new Error('Method not implemented.');
}

target(): Promise<void> {
throw new Error('Method not implemented.');
}
}

it('should apply the prefix', () => {
const module = new FakeModule({
prefix: 'CI_ONLY_',
});

expect(
module.prefix([
{
name: 'HELLO',
value: 'WORLD',
},
])
).toEqual([
{
name: 'CI_ONLY_HELLO',
value: 'WORLD',
},
]);
});

it('should return the original KeyInfos if no prefix is defined', () => {
const module = new FakeModule({});

expect(
module.prefix([
{
name: 'HELLO',
value: 'WORLD',
},
])
).toEqual([
{
name: 'HELLO',
value: 'WORLD',
},
]);
});
});
});
4 changes: 2 additions & 2 deletions packages/gitlab/src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export class GitLabSourceModule extends SourceModule {
private options: PartiallyRequired<Omit<GitLabSourceModule.Options, keyof SourceModule.Options>, 'token'>;
private token?: string;

constructor({ token, targets, ...options }: GitLabSourceModule.Options) {
super({ targets });
constructor({ token, prefix, targets, ...options }: GitLabSourceModule.Options) {
super({ targets, prefix });

this.options = {
...options,
Expand Down

0 comments on commit af7cbdd

Please sign in to comment.