<commit_before>// // tslint:disable:no-unused-expression
import 'mocha';

import { expect } from 'chai';

import { CompositeCollection, OAuth, Rest, setDefaultConfig, SObject, UsernamePasswordConfig } from '../..';
import { Account, Contact, User } from '../assets/sobs';

describe('Generated Classes', () => {
    before(async () => {
        const passwordConfig = new UsernamePasswordConfig(process.env.CLIENT_ID, process.env.CLIENT_SECRET, process.env.HOST, process.env.USERNAME, process.env.PASSWORD);
        let oAuth = new OAuth(passwordConfig);
        setDefaultConfig(await oAuth.initialize());
    });

    it('Parent Relationship', async () => {
        let acc = new Account({
            name: '<NAME>',
            website: 'example.com'
        });

        await acc.insert();
        expect(acc.id).to.not.be.null;

        let contact = new Contact({
            accountId: acc.id,
            firstName: `test`,
            lastName: `contact`
        });
        await contact.insert();

        let contact2 = (await Contact.retrieve(`SELECT ${Contact.FIELDS.name}, ${Contact.FIELDS.account}.${Account.FIELDS.website} FROM ${Contact.API_NAME} WHERE Id = '${contact.id}'`))[0];

        expect(contact2.account).to.not.be.null;
        expect(contact2.account.website).to.equal(acc.website);

        await acc.delete();
    });

    it('DML End-to-End', async () => {
        let acc = new Account({
            name: '<NAME>'
        });
        await acc.insert();
        expect(acc.id).to.not.be.null;

        acc.name = '<NAME>';
        await acc.update();

        let acc2 = (await Account.retrieve(`SELECT Name FROM Account WHERE Id = '${acc.id}'`))[0];

        expect(acc2.name).to.equal(acc.name);

        await acc.delete();

        let accounts = await Account.retrieve(`SELECT Name FROM Account WHERE Id = '${acc.id}'`);
        expect(accounts.length).to.equal(0);
    });

    it('Stale Memory', async () => {

        let acc = new Account({
            name: 'stale name'
        });
        await acc.insert();
        expect(acc.id).to.not.be.null;

        let acc2 = (await Account.retrieve(`SELECT Id, Name FROM Account WHERE Id = '${acc.id}'`))[0];
        expect(acc2.name).to.equal('stale name');

        acc2.name = '<NAME>';
        await acc2.update();

        // should not update in memory values which haven't been explicitly set!
        acc.website = 'example.com';
        await acc.update();

        let acc3 = (await Account.retrieve(`SELECT Name, Website FROM Account WHERE Id = '${acc.id}'`))[0];

        expect(acc3.website).to.equal(acc.website);
        expect(acc3.name).to.equal(acc2.name);

        //test update
        let acc4 = new Account({
            name: '<NAME>',
            id: acc.id
        });

        await acc4.update();
        let acc5 = (await Account.retrieve(`SELECT Name, Website FROM Account WHERE Id = '${acc.id}'`))[0];

        expect(acc5.name).to.equal(acc4.name);

        // Test preserve object

        console.log(acc4._modified);
        expect(acc4._modified.size).to.equal(0, 'expected modified to be cleared after update');

        let acc6 = new Account(acc4);
        expect(acc5._modified.size).to.equal(0);

        await acc.delete();
    });


    it('refresh', async () => {

        let acc = new Account({
            name: '<NAME>',
            website: 'www.facepamplet.com'
        });
        await acc.insert();
        let acc2 = (await Account.retrieve(`SELECT Id, Name FROM Account WHERE Id = '${acc.id}'`))[0];
        acc2.name = '<NAME>';
        acc2.billingCity = '23';
        await acc2.update({refresh: true});

        expect(acc2.website).to.equal(acc.website);

        await acc.delete();
    });
<commit_msg>added unit test for readonly with updateall<commit_after>// // tslint:disable:no-unused-expression
import 'mocha';

import { expect } from 'chai';

import { CompositeCollection, OAuth, Rest, setDefaultConfig, SObject, UsernamePasswordConfig } from '../..';
import { Account, Contact, User } from '../assets/sobs';

describe('Generated Classes', () => {
    before(async () => {
        const passwordConfig = new UsernamePasswordConfig(process.env.CLIENT_ID, process.env.CLIENT_SECRET, process.env.HOST, process.env.USERNAME, process.env.PASSWORD);
        let oAuth = new OAuth(passwordConfig);
        setDefaultConfig(await oAuth.initialize());
    });

    it('Parent Relationship', async () => {
        let acc = new Account({
            name: '<NAME>',
            website: 'example.com'
        });

        await acc.insert();
        expect(acc.id).to.not.be.null;

        let contact = new Contact({
            accountId: acc.id,
            firstName: `test`,
            lastName: `contact`
        });
        await contact.insert();

        let contact2 = (await Contact.retrieve(`SELECT ${Contact.FIELDS.name}, ${Contact.FIELDS.account}.${Account.FIELDS.website} FROM ${Contact.API_NAME} WHERE Id = '${contact.id}'`))[0];

        expect(contact2.account).to.not.be.null;
        expect(contact2.account.website).to.equal(acc.website);

        await acc.delete();
    });

    it('DML End-to-End', async () => {
        let acc = new Account({
            name: '<NAME>'
        });
        await acc.insert();
        expect(acc.id).to.not.be.null;

        acc.name = 'test name 2';
        await acc.update();

        let acc2 = (await Account.retrieve(`SELECT Name FROM Account WHERE Id = '${acc.id}'`))[0];

        expect(acc2.name).to.equal(acc.name);

        await acc.delete();

        let accounts = await Account.retrieve(`SELECT Name FROM Account WHERE Id = '${acc.id}'`);
        expect(accounts.length).to.equal(0);
    });

    it('Stale Memory', async () => {

        let acc = new Account({
            name: 'stale name'
        });
        await acc.insert();
        expect(acc.id).to.not.be.null;

        let acc2 = (await Account.retrieve(`SELECT Id, Name FROM Account WHERE Id = '${acc.id}'`))[0];
        expect(acc2.name).to.equal('stale name');

        acc2.name = '<NAME>';
        await acc2.update();

        // should not update in memory values which haven't been explicitly set!
        acc.website = 'example.com';
        await acc.update();

        let acc3 = (await Account.retrieve(`SELECT Name, Website FROM Account WHERE Id = '${acc.id}'`))[0];

        expect(acc3.website).to.equal(acc.website);
        expect(acc3.name).to.equal(acc2.name);

        //test update
        let acc4 = new Account({
            name: '<NAME>',
            id: acc.id
        });

        await acc4.update();
        let acc5 = (await Account.retrieve(`SELECT Name, Website FROM Account WHERE Id = '${acc.id}'`))[0];

        expect(acc5.name).to.equal(acc4.name);

        // Test preserve object

        console.log(acc4._modified);
        expect(acc4._modified.size).to.equal(0, 'expected modified to be cleared after update');

        let acc6 = new Account(acc4);
        expect(acc5._modified.size).to.equal(0);

        await acc.delete();
    });


    it('prepareFor Update all', async () => {

        let acc = new Account({
            name: 'account'
        });
        await acc.insert();

        let acc2 = (await Account.retrieve(`SELECT Id, Name, CreatedDate FROM Account WHERE Id = '${acc.id}'`))[0];

        let sob = acc2.prepareFor('update_all');

        expect(sob.CreatedDate).to.equal(undefined);

        await acc.delete();
    });


    it('refresh', async () => {

        let acc = new Account({
            name: '<NAME>',
            website: 'www.facepamplet.com'
        });
        await acc.insert();
        let acc2 = (await Account.retrieve(`SELECT Id, Name FROM Account WHERE Id = '${acc.id}'`))[0];
        acc2.name = '<NAME>';
        acc2.billingCity = '23';
        await acc2.update({refresh: true});

        expect(acc2.website).to.equal(acc.website);

        await acc.delete();
    });

{'fraction_non_alphanumeric': 0.16, 'fraction_numerical': 0.010314465408805032, 'mean_word_length': 2.2626179729175218, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4208169', 'n_tokens_mistral': 2431, 'n_tokens_neox': 2391, 'n_words': 546}