-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into pay-923-node-input-…
…output-search # Conflicts: # packages/editor-ui/src/utils/objectUtils.ts
- Loading branch information
Showing
8 changed files
with
205 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/cli/test/integration/commands/credentials.cmd.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as Config from '@oclif/config'; | ||
|
||
import { InternalHooks } from '@/InternalHooks'; | ||
import { ImportCredentialsCommand } from '@/commands/import/credentials'; | ||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials'; | ||
import * as testDb from '../shared/testDb'; | ||
import { mockInstance } from '../shared/utils'; | ||
|
||
beforeAll(async () => { | ||
mockInstance(InternalHooks); | ||
mockInstance(LoadNodesAndCredentials); | ||
await testDb.init(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await testDb.truncate(['Credentials']); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testDb.terminate(); | ||
}); | ||
|
||
test('import:credentials should import a credential', async () => { | ||
const config: Config.IConfig = new Config.Config({ root: __dirname }); | ||
const before = await testDb.getAllCredentials(); | ||
expect(before.length).toBe(0); | ||
const importer = new ImportCredentialsCommand( | ||
['--input=./test/integration/commands/importCredentials/credentials.json'], | ||
config, | ||
); | ||
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => { | ||
throw new Error('process.exit'); | ||
}); | ||
|
||
await importer.init(); | ||
try { | ||
await importer.run(); | ||
} catch (error) { | ||
expect(error.message).toBe('process.exit'); | ||
} | ||
const after = await testDb.getAllCredentials(); | ||
expect(after.length).toBe(1); | ||
expect(after[0].name).toBe('cred-aws-test'); | ||
expect(after[0].id).toBe('123'); | ||
expect(after[0].nodesAccess).toStrictEqual([]); | ||
mockExit.mockRestore(); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/cli/test/integration/commands/importCredentials/credentials.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"createdAt": "2023-07-10T14:50:49.193Z", | ||
"updatedAt": "2023-10-27T13:34:42.917Z", | ||
"id": "123", | ||
"name": "cred-aws-test", | ||
"data": { | ||
"region": "eu-west-1", | ||
"accessKeyId": "999999999999", | ||
"secretAccessKey": "aaaaaaaaaaaaa" | ||
}, | ||
"type": "aws", | ||
"nodesAccess": "" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
packages/editor-ui/src/utils/__tests__/objectUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { isObjectOrArray, isObject, searchInObject } from '@/utils'; | ||
|
||
const testData = [1, '', true, null, undefined, new Date(), () => {}].map((value) => [ | ||
value, | ||
typeof value, | ||
]); | ||
|
||
describe('objectUtils', () => { | ||
describe('isObjectOrArray', () => { | ||
it('should return true for objects', () => { | ||
assert(isObjectOrArray({})); | ||
}); | ||
|
||
it('should return true for arrays', () => { | ||
assert(isObjectOrArray([])); | ||
}); | ||
|
||
test.each(testData)('should return false for %j (type %s)', (value) => { | ||
assert(!isObjectOrArray(value)); | ||
}); | ||
}); | ||
|
||
describe('isObject', () => { | ||
it('should return true for objects', () => { | ||
assert(isObject({})); | ||
}); | ||
|
||
it('should return false for arrays', () => { | ||
assert(!isObject([])); | ||
}); | ||
|
||
test.each(testData)('should return false for %j (type %s)', (value) => { | ||
assert(!isObject(value)); | ||
}); | ||
}); | ||
|
||
describe('searchInObject', () => { | ||
it('should return true if the search string is found in the object', () => { | ||
assert(searchInObject({ a: 'b' }, 'b')); | ||
}); | ||
|
||
it('should return false if the search string is not found in the object', () => { | ||
assert(!searchInObject({ a: 'b' }, 'c')); | ||
}); | ||
|
||
it('should return true if the search string is not found in the object as a key', () => { | ||
assert(searchInObject({ a: 'b' }, 'a')); | ||
}); | ||
|
||
it('should return true if the search string is found in a nested object', () => { | ||
assert(searchInObject({ a: { b: 'c' } }, 'c')); | ||
}); | ||
|
||
it('should return true if the search string is found in a nested object as a key', () => { | ||
assert(searchInObject({ a: { b: 'c' } }, 'b')); | ||
}); | ||
|
||
it('should return true if the search string is found in an array', () => { | ||
assert(searchInObject(['a', 'b'], 'a')); | ||
}); | ||
|
||
it('should return true if the search string is found in a nested array', () => { | ||
assert(searchInObject(['a', ['b', 'c']], 'c')); | ||
}); | ||
|
||
it('should return false if the search string is not found in an array', () => { | ||
assert(!searchInObject(['a', 'b'], 'c')); | ||
}); | ||
|
||
it('should return false if the search string is not found in a nested array', () => { | ||
assert(!searchInObject(['a', ['b', 'c']], 'd')); | ||
}); | ||
|
||
it('should return true if the search string is found in a nested object in an array', () => { | ||
assert(searchInObject([{ a: 'b' }], 'b')); | ||
}); | ||
|
||
it('should return true if the search string is found in a nested array in an object', () => { | ||
assert(searchInObject({ a: ['b', 'c'] }, 'c')); | ||
}); | ||
|
||
it('should return false if the search string is not found in a nested object in an array', () => { | ||
assert(!searchInObject([{ a: 'b' }], 'c')); | ||
}); | ||
|
||
it('should return false if the search string is not found in a nested array in an object', () => { | ||
assert(!searchInObject({ a: ['b', 'c'] }, 'd')); | ||
}); | ||
|
||
it('should return true if the search string is found in an object as a key in a nested array', () => { | ||
assert(searchInObject({ a: ['b', { c: 'd' }] }, 'c')); | ||
}); | ||
|
||
it('should return true if the search string is found in an object in a nested array', () => { | ||
assert(searchInObject({ a: ['b', { c: 'd' }] }, 'd')); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters