Skip to content

Commit

Permalink
Add more tests for companyDomain block.
Browse files Browse the repository at this point in the history
  • Loading branch information
walery committed Aug 9, 2023
1 parent a9ec22b commit 384061f
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions test/companyDomain.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
const test = require('ava');

test.serial('should resolve companyDomain if companyName and companyTld provides default values', async t => {
test.serial('should resolve companyDomain if stencil:companyName and stencil:companyTld provides default values', async t => {
const actual = await resolveCompanyDomain();
t.is(actual, 'foo.bar');
t.is(actual, 'acme.bar');
});

test.serial('should resolve companyDomain if stencil:companyName and stencil:companyTld are overwritten', async t => {
const mockOverwrites = {
'stencil(account):companyName': Promise.resolve('inc'),
'stencil(account):companyTld': Promise.resolve('com'),
};

const actual = await resolveCompanyDomain(mockOverwrites);
t.is(actual, 'inc.com');
});

test.serial('should reject if stencil:companyTld is not resolvable', async t => {
const mockOverwrites = {
'stencil(account):companyTld': undefined,
};

const actual = await t.throwsAsync(
resolveCompanyDomain(mockOverwrites),
);
t.true(actual instanceof Error);
t.is(actual.message, 'Unknown variable expression \'stencil(account):companyTld\'.');
});

test.serial('should reject if stencil:companyName is not resolvable', async t => {
const mockOverwrites = {
'stencil(account):companyName': undefined,
};

const actual = await t.throwsAsync(
resolveCompanyDomain(mockOverwrites),
);
t.true(actual instanceof Error);
t.is(actual.message, 'Unknown variable expression \'stencil(account):companyName\'.');
});

test.serial('should reject if stencil:companyName and stencil:companyTld is not resolvable', async t => {
const mockOverwrites = {
'stencil(account):companyName': undefined,
'stencil(account):companyTld': undefined,
};

const actual = await t.throwsAsync(
resolveCompanyDomain(mockOverwrites),
);
t.true(actual instanceof Error);
t.is(actual.message, 'Unknown variable expression \'stencil(account):companyName\'.');
});

test.serial('should return cached result if resolution happens more than once', async t => {
const underTest = createUncachedInstance();
const actual = await underTest.resolve({
variableUtils: createVariableUtilsMock(),
});
t.is(actual, 'acme.bar');

const mockOverwrites = {
'stencil(account):companyName': undefined,
};

const actualCached = await underTest.resolve({
variableUtils: createVariableUtilsMock(mockOverwrites),
});
t.is(actualCached, 'acme.bar');
});

const resolveCompanyDomain = (overwrites = {}) => {
Expand All @@ -19,7 +83,7 @@ const createUncachedInstance = () => {

const createVariableUtilsMock = overwrites => {
const resolveVariableValues = {
'stencil(account):companyName': Promise.resolve('foo'),
'stencil(account):companyName': Promise.resolve('acme'),
'stencil(account):companyTld': Promise.resolve('bar'),
};
Object.assign(resolveVariableValues, overwrites);
Expand Down

0 comments on commit 384061f

Please sign in to comment.