-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hosting: Add testing coverage to SFTP/phpMyAdmin data layer (#38046)
Adds testing coverage for all the SFTP/phpMyAdmin reducers and selectors available in the state. This also removes some tests added in #37966 that were just mere boilerplate to double check implementations details rather than behavior. Such tests are discouraged by our unit testing guidelines.
- Loading branch information
Showing
6 changed files
with
214 additions
and
70 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
32 changes: 0 additions & 32 deletions
32
client/state/data-layer/wpcom/sites/rewind/backups/test/index.js
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import deepFreeze from 'deep-freeze'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import reducer, { sftpUsers } from '../reducer'; | ||
import { HOSTING_SFTP_USERS_SET, HOSTING_SFTP_USER_UPDATE, SERIALIZE } from 'state/action-types'; | ||
import { useSandbox } from 'test/helpers/use-sinon'; | ||
|
||
describe( 'reducer', () => { | ||
useSandbox( sandbox => { | ||
sandbox.stub( console, 'warn' ); | ||
} ); | ||
|
||
describe( '#sftpUsers()', () => { | ||
test( 'should default to an empty object', () => { | ||
const state = sftpUsers( undefined, {} ); | ||
|
||
expect( state ).toEqual( {} ); | ||
} ); | ||
|
||
test( 'should set given users', () => { | ||
const state = sftpUsers( undefined, { | ||
type: HOSTING_SFTP_USERS_SET, | ||
users: [ 1, 2, 3 ], | ||
} ); | ||
|
||
expect( state ).toEqual( [ 1, 2, 3 ] ); | ||
} ); | ||
|
||
test( 'should override previous users', () => { | ||
const previousState = deepFreeze( [ 1, 2, 3 ] ); | ||
const state = sftpUsers( previousState, { | ||
type: HOSTING_SFTP_USERS_SET, | ||
users: [ 4, 5, 6 ], | ||
} ); | ||
|
||
expect( state ).toEqual( [ 4, 5, 6 ] ); | ||
} ); | ||
|
||
test( 'should persist state', () => { | ||
const previousState = deepFreeze( [ 1, 2, 3 ] ); | ||
const state = sftpUsers( previousState, { type: SERIALIZE } ); | ||
|
||
expect( state ).toEqual( [ 1, 2, 3 ] ); | ||
} ); | ||
|
||
test( 'should update existing users', () => { | ||
const previousState = deepFreeze( [ | ||
{ username: 'u1', password: 'p1' }, | ||
{ username: 'u2', password: 'p2' }, | ||
{ username: 'u3', password: 'p3' }, | ||
] ); | ||
const state = sftpUsers( previousState, { | ||
type: HOSTING_SFTP_USER_UPDATE, | ||
users: [ { username: 'u2', password: 'p2-updated' } ], | ||
} ); | ||
|
||
expect( state ).toEqual( [ | ||
{ username: 'u1', password: 'p1' }, | ||
{ username: 'u2', password: 'p2-updated' }, | ||
{ username: 'u3', password: 'p3' }, | ||
] ); | ||
} ); | ||
|
||
test( 'should not update non-existing users', () => { | ||
const previousState = deepFreeze( [ | ||
{ username: 'u1', password: 'p1' }, | ||
{ username: 'u2', password: 'p2' }, | ||
{ username: 'u3', password: 'p3' }, | ||
] ); | ||
const state = sftpUsers( previousState, { | ||
type: HOSTING_SFTP_USER_UPDATE, | ||
users: [ { username: 'u4', password: 'p4' } ], | ||
} ); | ||
|
||
expect( state ).toEqual( [ | ||
{ username: 'u1', password: 'p1' }, | ||
{ username: 'u2', password: 'p2' }, | ||
{ username: 'u3', password: 'p3' }, | ||
] ); | ||
} ); | ||
|
||
test( 'should not update if there are no users', () => { | ||
const state = sftpUsers( undefined, { | ||
type: HOSTING_SFTP_USER_UPDATE, | ||
users: [ { username: 'u1', password: 'p1' } ], | ||
} ); | ||
|
||
expect( state ).toEqual( {} ); | ||
} ); | ||
} ); | ||
|
||
test( 'should default to an empty object', () => { | ||
const state = reducer( undefined, {} ); | ||
|
||
expect( state ).toEqual( {} ); | ||
} ); | ||
|
||
test( 'should map site ID', () => { | ||
const state = reducer( undefined, { | ||
type: HOSTING_SFTP_USERS_SET, | ||
users: [ 1, 2, 3 ], | ||
siteId: 12345678, | ||
} ); | ||
|
||
expect( state ).toEqual( { | ||
12345678: { | ||
sftpUsers: [ 1, 2, 3 ], | ||
}, | ||
} ); | ||
} ); | ||
|
||
test( 'should accumulate sites', () => { | ||
const previousState = { | ||
12345678: { | ||
sftpUsers: [ 1, 2, 3 ], | ||
}, | ||
}; | ||
const state = reducer( previousState, { | ||
type: HOSTING_SFTP_USERS_SET, | ||
users: [ 9, 8, 7 ], | ||
siteId: 9876543, | ||
} ); | ||
|
||
expect( state ).toEqual( { | ||
12345678: { | ||
sftpUsers: [ 1, 2, 3 ], | ||
}, | ||
9876543: { | ||
sftpUsers: [ 9, 8, 7 ], | ||
}, | ||
} ); | ||
} ); | ||
} ); |
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
client/state/selectors/test/get-atomic-hosting-sftp-users.js
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,62 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getAtomicHostingSftpUsers } from 'state/selectors/get-atomic-hosting-sftp-users'; | ||
|
||
describe( 'getAtomicHostingSftpUsers()', () => { | ||
test( 'should return null if there is no hosting data', () => { | ||
const state = {}; | ||
const users = getAtomicHostingSftpUsers( state, 123 ); | ||
|
||
expect( users ).toBeNull(); | ||
} ); | ||
|
||
test( 'should return null if the site is not tracked', () => { | ||
const state = { | ||
atomicHosting: { | ||
123: { | ||
sftpUsers: [ | ||
{ username: 'u1', password: 'p1' }, | ||
{ username: 'u2', password: 'p3' }, | ||
{ username: 'u3', password: 'p3' }, | ||
], | ||
}, | ||
}, | ||
}; | ||
const users = getAtomicHostingSftpUsers( state, 124 ); | ||
|
||
expect( users ).toBeNull(); | ||
} ); | ||
|
||
test( 'should return null if there are no users data', () => { | ||
const state = { | ||
atomicHosting: { | ||
123: {}, | ||
}, | ||
}; | ||
const users = getAtomicHostingSftpUsers( state, 123 ); | ||
|
||
expect( users ).toBeNull(); | ||
} ); | ||
|
||
test( 'should return list of users', () => { | ||
const state = { | ||
atomicHosting: { | ||
123: { | ||
sftpUsers: [ | ||
{ username: 'u1', password: 'p1' }, | ||
{ username: 'u2', password: 'p3' }, | ||
{ username: 'u3', password: 'p3' }, | ||
], | ||
}, | ||
}, | ||
}; | ||
const users = getAtomicHostingSftpUsers( state, 123 ); | ||
|
||
expect( users ).toEqual( [ | ||
{ username: 'u1', password: 'p1' }, | ||
{ username: 'u2', password: 'p3' }, | ||
{ username: 'u3', password: 'p3' }, | ||
] ); | ||
} ); | ||
} ); |