@test('Inserting a new transaction fails if OrderId is invalid') public async invalidOrder() { let db = await getDb(); let errors: string[] = []; try { let transaction = await db.run( sql` INSERT INTO CustomerOrderTransaction(auth, orderid) VALUES ($1, $2)`, 'lk1hdklh12ld', 191927158 ); assert.ok(false, 'Should have encountered a foreign key constraint error'); } catch (e) { errors.push(e.toString()); } assert.isAtLeast( errors.length, 1, 'At least one error (foreign key constraint violation) should have been thrown' ); assert.include( errors[0].toLowerCase(), 'foreign key', 'Error message says something about "foreign key' ); }
it('should wait at least 2 seconds', async () => { const now = new Date().getTime(); const in2secs = now + 2000; await wait(2000); assert.isAtLeast(new Date().getTime(), in2secs); });
it('should create a Redux store that responds to actions', (done: MochaDone) => { const store = createReduxStore(); const state = store.getState(); assert.isAtLeast(Object.keys(state).length, 1); const unsubscribe = store.subscribe(() => done()); store.dispatch({type: 'testAction'} as any); unsubscribe(); });
export function assertMigrationCount( migrationCount: number, sqlsCount = migrationCount ) { assert.ok( fs.existsSync(path.join(__dirname, '..', '..', 'migrations')), './migrations folder exists' ); let migrationsFiles = fs.readdirSync( path.join(__dirname, '..', '..', 'migrations') ); assert.ok( fs.existsSync(path.join(__dirname, '..', '..', 'migrations', 'sqls')), './sqls folder exists' ); assert.includeDeepMembers( migrationsFiles, ['sqls', '20171203034929-first.ts'], './migrations folder contains sqls folder and first migration' ); assert.isAtLeast( migrationsFiles.length, migrationCount, `There are at least ${migrationCount} things in the ./migrations folder` ); let migrationsSqlsFiles = fs.readdirSync( path.join(__dirname, '..', '..', 'migrations', 'sqls') ); assert.isAtLeast( migrationsSqlsFiles.length, sqlsCount, `There are at least ${sqlsCount} things in the ./migrations/sqls folder` ); let downMigrationCount = 0; let upMigrationCount = 0; migrationsSqlsFiles.forEach(fileName => { if (fileName.includes('-down')) { downMigrationCount++; } if (fileName.includes('-up')) { upMigrationCount++; } }); }
it("should verify parse Exe output - delete a file that doesn't exist - error exit code", async function() { const noChangesPaths: string[] = [path.join("folder1", "folder2", "foo.txt")]; const localPaths: string[] = noChangesPaths; const cmd: Delete = new Delete(undefined, localPaths); const executionResult: IExecutionResult = { exitCode: 100, stdout: "The item C:\\repos\\Tfvc.L2VSCodeExtension.RC\\folder1\\folder2\\foo.txt could not be found in your workspace, or you do not have permission to access it.\n" + "No arguments matched any files to delete.\n", stderr: undefined }; try { await cmd.ParseExeOutput(executionResult); } catch (err) { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "delete"); assert.isAtLeast(err.stdout.indexOf("could not be found in your workspace"), 0); assert.isAtLeast(err.stdout.indexOf("No arguments matched any files to delete"), 0); } });
@test('createOrder() creates an order successfully for valid data') public async createOrderForValidData() { let o = await createOrder(VALID_ORDER_DATA as any); assert.ok(o, 'returns a promise that resolves to a non-empty vale'); assert.ok(o.id, 'returns a promise that resolves to something with an id property'); assert.isAtLeast( parseInt(o.id as string, 10), 1, 'returns a promise that resolves to something with a numeric id property, whose value is > 1' ); }
@test('getAllProducts() (no filter) still works as expected') public async allProducts() { let result = await getAllProducts(); assert.isArray(result, 'Expected result to be an array'); // TODO: tighten assertion assert.isAtLeast( result.length, 50, 'Expected at least 50 products in array' ); assertProductCols(result[0]); }
it("should verify parse Exe output - deletion conflict - error exit code", async function() { const noChangesPaths: string[] = [path.join("folder1", "folder2")]; const localPaths: string[] = noChangesPaths; const cmd: Delete = new Delete(undefined, localPaths); const executionResult: IExecutionResult = { exitCode: 100, stdout: "// TF203069: $/L2.VSCodeExtension.RC/folder1/folder2 could not be deleted because that change " + "conflicts with one or more other pending changes to that item. To delete it, undo all pending changes " + "to that item, delete it, and then check in the change.\n" + "No arguments matched any files to delete.\n", stderr: undefined }; try { await cmd.ParseExeOutput(executionResult); } catch (err) { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "delete"); assert.isAtLeast(err.stdout.indexOf("TF203069: "), 0); assert.isAtLeast(err.stdout.indexOf("No arguments matched any files to delete"), 0); } });
@test('All products') public async allProducts() { let result = await getAllProducts(); assert.isArray(result, 'Expected result to be an array'); // TODO: tighten assertion assert.isAtLeast(result.length, 50, 'Expected at least 50 products in array'); validateRecordColumns( { recordType: 'product', functionName: 'getAllProducts' }, result[3], REQUIRED_PRODUCT_LIST_COLS, FORBIDDEN_PRODUCT_LIST_COLS ); }
@test('filter="fre" returns subset of results') public async filteredCustomers1() { let result = await getAllCustomers({ filter: 'fre' }); assert.isArray(result, 'Expected result to be an array'); assert.isAtLeast(result.length, 3, 'Expected 3 or more customers in array'); assert.isAtMost(result.length, 5, 'Expected 5 or fewer customers in array'); validateRecordColumns( { recordType: 'customer', functionName: 'getAllCustomers({ filter: "fre" })' }, result[0], ALL_CUSTOMERS_REQUIRED_COLS, [] ); }