Skip to content

Commit

Permalink
fix(core): update cloud dependency, cloud client calls
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe committed Apr 18, 2024
1 parent 26c215f commit 75a0348
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/connectors/connector-logto-email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"access": "public"
},
"devDependencies": {
"@logto/cloud": "0.2.5-821690c",
"@logto/cloud": "0.2.5-e5d8200",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@fontsource/roboto-mono": "^5.0.0",
"@jest/types": "^29.5.0",
"@logto/app-insights": "workspace:^1.4.0",
"@logto/cloud": "0.2.5-821690c",
"@logto/cloud": "0.2.5-e5d8200",
"@logto/connector-kit": "workspace:^3.0.0",
"@logto/core-kit": "workspace:^2.4.0",
"@logto/language-kit": "workspace:^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@logto/cloud": "0.2.5-821690c",
"@logto/cloud": "0.2.5-e5d8200",
"@silverhand/eslint-config": "5.0.0",
"@silverhand/ts-config": "5.0.0",
"@types/debug": "^4.1.7",
Expand Down
357 changes: 357 additions & 0 deletions packages/core/src/libraries/logto-config.script-merging.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,357 @@
import { LogtoJwtTokenKey } from '@logto/schemas';
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', () => {
it.each(Object.values(LogtoJwtTokenKey))('test %s script', (key) => {
expect(
deepmerge(
{
[LogtoJwtTokenKey.AccessToken]: {
production: `${LogtoJwtTokenKey.AccessToken}-production`,
},
[LogtoJwtTokenKey.ClientCredentials]: {
production: `${LogtoJwtTokenKey.ClientCredentials}-production`,
},
},
{
[key]: {
test: `${key}-test`,
},
}
)
).toEqual({
[LogtoJwtTokenKey.AccessToken]: {
production: `${LogtoJwtTokenKey.AccessToken}-production`,
...cond(key === LogtoJwtTokenKey.AccessToken && { test: `${key}-test` }),
},
[LogtoJwtTokenKey.ClientCredentials]: {
production: `${LogtoJwtTokenKey.ClientCredentials}-production`,
...cond(key === LogtoJwtTokenKey.ClientCredentials && { test: `${key}-test` }),
},
});
});
});

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`,
(testingKey) => {
const workingKey = LogtoJwtTokenKey.AccessToken;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
[testingKey]: {
test: `${testingKey}-test`,
},
})
).toEqual(
workingKey === testingKey
? {
[workingKey]: {
production: `${workingKey}-production`,
test: `${workingKey}-test`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
},
[testingKey]: {
test: `${testingKey}-test`,
},
}
);
}
);

it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.ClientCredentials} script is working, test $s script`,
(testingKey) => {
const workingKey = LogtoJwtTokenKey.ClientCredentials;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
[testingKey]: {
test: `${testingKey}-test`,
},
})
).toEqual(
workingKey === testingKey
? {
[workingKey]: {
production: `${workingKey}-production`,
test: `${workingKey}-test`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
},
[testingKey]: {
test: `${testingKey}-test`,
},
}
);
}
);
});

describe('Test script when both AccessToken & ClientCredentials scripts are not working', () => {
it.each(Object.values(LogtoJwtTokenKey))('test %s script', (key) => {
expect(
deepmerge(
{},
{
[key]: `${key}-test`,
}
)
).toEqual({
[key]: `${key}-test`,
});
});
});
});

describe('Test deploy custom JWT script', () => {
describe('Deploy script when both AccessToken & ClientCredentials scripts are working', () => {
it.each(Object.values(LogtoJwtTokenKey))('deploy %s script', (key) => {
expect(
deepmerge(
{
[LogtoJwtTokenKey.AccessToken]: {
production: `${LogtoJwtTokenKey.AccessToken}-production`,
},
[LogtoJwtTokenKey.ClientCredentials]: {
production: `${LogtoJwtTokenKey.ClientCredentials}-production`,
},
},
{
[key]: {
production: `${key}-production-new`,
},
}
)
).toEqual({
[LogtoJwtTokenKey.AccessToken]: {
production: `${LogtoJwtTokenKey.AccessToken}-production${
key === LogtoJwtTokenKey.AccessToken ? '-new' : ''
}`,
},
[LogtoJwtTokenKey.ClientCredentials]: {
production: `${LogtoJwtTokenKey.ClientCredentials}-production${
key === LogtoJwtTokenKey.ClientCredentials ? '-new' : ''
}`,
},
});
});
});

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`,
(deployingKey) => {
const workingKey = LogtoJwtTokenKey.AccessToken;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
[deployingKey]: {
production: `${deployingKey}-production-new`,
},
})
).toEqual(
workingKey === deployingKey
? {
[workingKey]: {
production: `${workingKey}-production-new`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
},
[deployingKey]: {
production: `${deployingKey}-production-new`,
},
}
);
}
);

it.each(Object.values(LogtoJwtTokenKey))(
`when ${LogtoJwtTokenKey.ClientCredentials} script is working, deploy $s script`,
(deployingKey) => {
const workingKey = LogtoJwtTokenKey.ClientCredentials;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
[deployingKey]: {
production: `${deployingKey}-production-new`,
},
})
).toEqual(
workingKey === deployingKey
? {
[workingKey]: {
production: `${workingKey}-production-new`,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
},
[deployingKey]: {
production: `${deployingKey}-production-new`,
},
}
);
}
);
});

describe('Deploy script when both AccessToken & ClientCredentials scripts are not working', () => {
it.each(Object.values(LogtoJwtTokenKey))('deploy %s script', (key) => {
expect(
deepmerge(
{},
{
[key]: {
production: `${key}-production-new`,
},
}
)
).toEqual({
[key]: {
production: `${key}-production-new`,
},
});
});
});
});

describe('Test undeploy custom JWT script', () => {
describe('Undeploy script when both AccessToken & ClientCredentials scripts are working', () => {
it.each(Object.values(LogtoJwtTokenKey))('undeploy %s script', (key) => {
expect(
deepmerge(
{
[LogtoJwtTokenKey.AccessToken]: {
production: `${LogtoJwtTokenKey.AccessToken}-production`,
},
[LogtoJwtTokenKey.ClientCredentials]: {
production: `${LogtoJwtTokenKey.ClientCredentials}-production`,
},
},
{
[key]: {
production: undefined,
},
}
)
).toEqual({
[LogtoJwtTokenKey.AccessToken]: {
production:
key === LogtoJwtTokenKey.AccessToken
? undefined
: `${LogtoJwtTokenKey.AccessToken}-production`,
},
[LogtoJwtTokenKey.ClientCredentials]: {
production:
key === LogtoJwtTokenKey.ClientCredentials
? undefined
: `${LogtoJwtTokenKey.ClientCredentials}-production`,
},
});
});
});

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`,
(undeployingKey) => {
const workingKey = LogtoJwtTokenKey.AccessToken;
const workingScript = {
[workingKey]: {
production: `${workingKey}-production`,
},
};
expect(
deepmerge(workingScript, {
[undeployingKey]: {
production: undefined,
},
})
).toEqual(
workingKey === undeployingKey
? {
[workingKey]: {
production: undefined,
},
}
: {
[workingKey]: {
production: `${workingKey}-production`,
},
[undeployingKey]: {
production: undefined,
},
}
);
}
);

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

0 comments on commit 75a0348

Please sign in to comment.