File size: 4,045 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
import { SiteExcerptData } from '@automattic/sites';
import { getMigrationState, getMigrationStatus, isMigrationInProgress } from '../index';
describe( 'getMigrationState', () => {
it( 'returns status pending and type difm for migration-pending-difm', () => {
const migrationInfo = {
migration_status: 'migration-pending-difm',
};
expect( getMigrationState( migrationInfo ) ).toEqual( {
status: 'pending',
type: 'difm',
} );
} );
it( 'returns status started and type difm for migration-started-difm', () => {
const migrationInfo = {
migration_status: 'migration-started-difm',
};
expect( getMigrationState( migrationInfo ) ).toEqual( {
status: 'started',
type: 'difm',
} );
} );
it( 'returns status pending and type diy for migration-pending-diy', () => {
const migrationInfo = {
migration_status: 'migration-pending-diy',
};
expect( getMigrationState( migrationInfo ) ).toEqual( {
status: 'pending',
type: 'diy',
} );
} );
it( 'returns status started and type diy for migration-started-diy', () => {
const migrationInfo = {
migration_status: 'migration-started-diy',
};
expect( getMigrationState( migrationInfo ) ).toEqual( {
status: 'started',
type: 'diy',
} );
} );
it( 'returns type DIFM and status started when the migration was started by DAMS', () => {
const migrationInfo = {
migration_status: 'migration-in-progress',
};
expect( getMigrationState( migrationInfo ) ).toEqual( {
status: 'started',
type: 'difm',
} );
} );
it( 'returns null when migration info is not defined', () => {
expect( getMigrationState( undefined ) ).toEqual( null );
} );
it( 'returns null when the migration info > migration_status is not defined', () => {
const migrationInfo = {
in_progress: false,
};
expect( getMigrationState( migrationInfo ) ).toEqual( null );
} );
it( 'returns null when the type is not supported', () => {
const migrationInfo = {
migration_status: 'migration-pending-unknown',
};
expect( getMigrationState( migrationInfo ) ).toEqual( null );
} );
it( 'returns null when the status is not supported', () => {
const migrationInfo = {
migration_status: 'migration-unknown-difm',
};
expect( getMigrationState( migrationInfo ) ).toEqual( null );
} );
} );
describe( 'isMigrationInProgress', () => {
it.each( [
null,
{ site: {} },
{ site: { site_migration: { migration_status: 'migration-completed-diy' } } },
{ site: { site_migration: { migration_status: 'migration-completed-difm' } } },
{ site: { site_migration: { migration_status: 'migration-cancelled-difm' } } },
] )( 'returns false when the migration is not in progress', ( scenario ) => {
return expect( isMigrationInProgress( scenario?.site as SiteExcerptData ) ).toBe( false );
} );
it.each( [
{ site: { site_migration: { migration_status: 'migration-started-diy' } } },
{ site: { site_migration: { migration_status: 'migration-pending-diy' } } },
{ site: { site_migration: { migration_status: 'migration-in-progress' } } },
] )( 'returns true when the migration is in progress', ( scenario ) => {
return expect( isMigrationInProgress( scenario?.site as SiteExcerptData ) ).toBe( true );
} );
} );
describe( 'getMigrationStatus', () => {
it.each( [
{
site: { site_migration: { migration_status: 'migration-started-difm' } },
expected: 'started',
},
{
site: { site_migration: { migration_status: 'migration-pending-diy' } },
expected: 'pending',
},
{
site: { site_migration: { migration_status: 'migration-completed-difm' } },
expected: 'completed',
},
{
site: { site_migration: { migration_status: 'migration-unknown-anything' } },
expected: null,
},
{
site: { site_migration: {} },
expected: null,
},
{
site: {},
expected: null,
},
] )(
'returns $expected for migration status $site.site_migration.migration_status',
( scenario ) => {
expect( getMigrationStatus( scenario?.site as SiteExcerptData ) ).toBe( scenario?.expected );
}
);
} );
|