Skip to content

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Gao Sun <gao@silverhand.io>
  • Loading branch information
darcyYe and gao-sun committed Apr 18, 2024
1 parent c9c213b commit ff163b7
Showing 1 changed file with 71 additions and 71 deletions.
142 changes: 71 additions & 71 deletions packages/core/src/libraries/logto-config.script-merging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cond } from '@silverhand/essentials';
import deepmerge from 'deepmerge';

describe('Test the deploy custom JWT script', () => {
describe('Test script when both AccessToken & ClientCredentials scripts are working', () => {
describe('Test script when both AccessToken & ClientCredentials scripts are existing', () => {
it.each(Object.values(LogtoJwtTokenKey))('test %s script', (key) => {
expect(
deepmerge(
Expand Down Expand Up @@ -37,31 +37,31 @@ describe('Test the deploy custom JWT script', () => {
describe('Test script:', () => {
// Test it.each() can not be nested, so we have to test each key separately.
it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.AccessToken} script is working, test $s script`,
`when ${LogtoJwtTokenKey.AccessToken} script is existing, test $s script`,
(testingKey) => {
const workingKey = LogtoJwtTokenKey.AccessToken;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
const existingKey = LogtoJwtTokenKey.AccessToken;
const existingScript = {
[existingKey]: {
production: `${existingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
deepmerge(existingScript, {
[testingKey]: {
test: `${testingKey}-test`,
},
})
).toEqual(
workingKey === testingKey
existingKey === testingKey
? {
[workingKey]: {
production: `${workingKey}-production`,
test: `${workingKey}-test`,
[existingKey]: {
production: `${existingKey}-production`,
test: `${existingKey}-test`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
[existingKey]: {
production: `${existingKey}-production`,
},
[testingKey]: {
test: `${testingKey}-test`,
Expand All @@ -72,31 +72,31 @@ describe('Test the deploy custom JWT script', () => {
);

it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.ClientCredentials} script is working, test $s script`,
`when ${LogtoJwtTokenKey.ClientCredentials} script is existing, test $s script`,
(testingKey) => {
const workingKey = LogtoJwtTokenKey.ClientCredentials;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
const existingKey = LogtoJwtTokenKey.ClientCredentials;
const existingScript = {
[existingKey]: {
production: `${existingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
deepmerge(existingScript, {
[testingKey]: {
test: `${testingKey}-test`,
},
})
).toEqual(
workingKey === testingKey
existingKey === testingKey
? {
[workingKey]: {
production: `${workingKey}-production`,
test: `${workingKey}-test`,
[existingKey]: {
production: `${existingKey}-production`,
test: `${existingKey}-test`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
[existingKey]: {
production: `${existingKey}-production`,
},
[testingKey]: {
test: `${testingKey}-test`,
Expand All @@ -107,7 +107,7 @@ describe('Test the deploy custom JWT script', () => {
);
});

describe('Test script when both AccessToken & ClientCredentials scripts are not working', () => {
describe('Test script when both AccessToken & ClientCredentials scripts are not existing', () => {
it.each(Object.values(LogtoJwtTokenKey))('test %s script', (key) => {
expect(
deepmerge(
Expand All @@ -124,7 +124,7 @@ describe('Test the deploy custom JWT script', () => {
});

describe('Test deploy custom JWT script', () => {
describe('Deploy script when both AccessToken & ClientCredentials scripts are working', () => {
describe('Deploy script when both AccessToken & ClientCredentials scripts are existing', () => {
it.each(Object.values(LogtoJwtTokenKey))('deploy %s script', (key) => {
expect(
deepmerge(
Expand Down Expand Up @@ -160,30 +160,30 @@ describe('Test deploy custom JWT script', () => {
describe('Deploy script:', () => {
// Test it.each() can not be nested, so we have to test each key separately.
it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.AccessToken} script is working, deploy $s script`,
`when ${LogtoJwtTokenKey.AccessToken} script is existing, deploy $s script`,
(deployingKey) => {
const workingKey = LogtoJwtTokenKey.AccessToken;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
const existingKey = LogtoJwtTokenKey.AccessToken;
const existingScript = {
[existingKey]: {
production: `${existingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
deepmerge(existingScript, {
[deployingKey]: {
production: `${deployingKey}-production-new`,
},
})
).toEqual(
workingKey === deployingKey
existingKey === deployingKey
? {
[workingKey]: {
production: `${workingKey}-production-new`,
[existingKey]: {
production: `${existingKey}-production-new`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
[existingKey]: {
production: `${existingKey}-production`,
},
[deployingKey]: {
production: `${deployingKey}-production-new`,
Expand All @@ -194,30 +194,30 @@ describe('Test deploy custom JWT script', () => {
);

it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.ClientCredentials} script is working, deploy $s script`,
`when ${LogtoJwtTokenKey.ClientCredentials} script is existing, deploy $s script`,
(deployingKey) => {
const workingKey = LogtoJwtTokenKey.ClientCredentials;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
const existingKey = LogtoJwtTokenKey.ClientCredentials;
const existingScript = {
[existingKey]: {
production: `${existingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
deepmerge(existingScript, {
[deployingKey]: {
production: `${deployingKey}-production-new`,
},
})
).toEqual(
workingKey === deployingKey
existingKey === deployingKey
? {
[workingKey]: {
production: `${workingKey}-production-new`,
[existingKey]: {
production: `${existingKey}-production-new`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
[existingKey]: {
production: `${existingKey}-production`,
},
[deployingKey]: {
production: `${deployingKey}-production-new`,
Expand All @@ -228,7 +228,7 @@ describe('Test deploy custom JWT script', () => {
);
});

describe('Deploy script when both AccessToken & ClientCredentials scripts are not working', () => {
describe('Deploy script when both AccessToken & ClientCredentials scripts are not existing', () => {
it.each(Object.values(LogtoJwtTokenKey))('deploy %s script', (key) => {
expect(
deepmerge(
Expand All @@ -249,7 +249,7 @@ describe('Test deploy custom JWT script', () => {
});

describe('Test undeploy custom JWT script', () => {
describe('Undeploy script when both AccessToken & ClientCredentials scripts are working', () => {
describe('Undeploy script when both AccessToken & ClientCredentials scripts are existing', () => {
it.each(Object.values(LogtoJwtTokenKey))('undeploy %s script', (key) => {
expect(
deepmerge(
Expand Down Expand Up @@ -287,30 +287,30 @@ describe('Test undeploy custom JWT script', () => {
describe('Undeploy script:', () => {
// Test it.each() can not be nested, so we have to test each key separately.
it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.AccessToken} script is working, undeploy $s script`,
`when ${LogtoJwtTokenKey.AccessToken} script is existing, undeploy $s script`,
(undeployingKey) => {
const workingKey = LogtoJwtTokenKey.AccessToken;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
const existingKey = LogtoJwtTokenKey.AccessToken;
const existingScript = {
[existingKey]: {
production: `${existingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
deepmerge(existingScript, {
[undeployingKey]: {
production: undefined,
},
})
).toEqual(
workingKey === undeployingKey
existingKey === undeployingKey
? {
[workingKey]: {
[existingKey]: {
production: undefined,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
[existingKey]: {
production: `${existingKey}-production`,
},
[undeployingKey]: {
production: undefined,
Expand All @@ -321,30 +321,30 @@ describe('Test undeploy custom JWT script', () => {
);

it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.ClientCredentials} script is working, undeploy $s script`,
`when ${LogtoJwtTokenKey.ClientCredentials} script is existing, undeploy $s script`,
(undeployingKey) => {
const workingKey = LogtoJwtTokenKey.ClientCredentials;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
const existingKey = LogtoJwtTokenKey.ClientCredentials;
const existingScript = {
[existingKey]: {
production: `${existingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
deepmerge(existingScript, {
[undeployingKey]: {
production: undefined,
},
})
).toEqual(
workingKey === undeployingKey
existingKey === undeployingKey
? {
[workingKey]: {
[existingKey]: {
production: undefined,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
[existingKey]: {
production: `${existingKey}-production`,
},
[undeployingKey]: {
production: undefined,
Expand Down

0 comments on commit ff163b7

Please sign in to comment.