<commit_before>import Stardog from './index';

jest.setTimeout(10000);

const testDb = 'test';

const stardog = new Stardog({
    endpoint: 'http://localhost:5820',
    database: testDb,
    auth: {
        user: 'admin',
        pass: '<PASSWORD>'
    }
});

beforeAll(async () => {
    await stardog.createDatabase({
        database: testDb
    });

    await stardog.update({
        query: 'insert data {<urn:a> <urn:b> <urn:c>}'
    });
});

afterAll(async () => {
    await stardog.dropDatabase({
        database: testDb
    });
});

describe('database', () => {
    test('create', async () => {
        await stardog.createDatabase({
            database: 'create'
        });

        expect(await stardog.existsDatabase({
            database: 'create'
        })).toBeTruthy();

        await stardog.dropDatabase({
            database: 'create'
        });
    });

    test('drop', async () => {
        await stardog.createDatabase({
            database: 'drop'
        });

        expect(await stardog.existsDatabase({
            database: 'drop'
        })).toBeTruthy();

        await stardog.dropDatabase({
            database: 'drop'
        });

        expect(await stardog.existsDatabase({
            database: 'drop'
        })).toBeFalsy();
    });

    test('size', async () => {
        expect(await stardog.sizeDatabase({
            database: testDb
        })).toBe(1);
    });

    test('list', async () => {
        expect(await stardog.listDatabases()).toContain(testDb);
    });

    test('exists', async () => {
        expect(await stardog.existsDatabase({
            database: testDb
        })).toBeTruthy();

        expect(await stardog.existsDatabase({
            database: testDb + '2'
        })).toBeFalsy();
    });
});

describe('query', () => {
    test('ask', async () => {
        expect(await stardog.query({
            accept: 'text/boolean',
            query: 'ask {<urn:a> <urn:b> <urn:c>}'
        })).toBeTruthy();

        expect(await stardog.query({
            accept: 'text/boolean',
            query: 'ask {<urn:a> <urn:b> <urn:d>}'
        })).toBeFalsy();
    });

    test('select', async () => {
        expect(await stardog.query({
            query: 'select * where {?s ?p ?o}'
        })).toEqual({
            head: {vars: ['s', 'p', 'o']},
            results: {
                bindings: [{
                    s: {type: 'uri', value: 'urn:a'},
                    o: {type: 'uri', value: 'urn:c'},
                    p: {type: 'uri', value: 'urn:b'}
                }]
            }
        });
    });

    test('construct', async () => {
        expect(await stardog.query({
            query: 'construct {?s ?p ?o} where {?s ?p ?o}'
        })).toBe('\r\n<urn:a> <urn:b> <urn:c> .\r\n');
    });
});

describe('update', () => {
    test('insert', async () => {
        await stardog.update({
            query: 'insert data {<urn:a> <urn:b> <urn:c>}'
        });
    });
});<commit_msg>Add update tests<commit_after>import Stardog from './index';

jest.setTimeout(10000);

const testDb = 'test';

const stardog = new Stardog({
    endpoint: 'http://localhost:5820',
    database: testDb,
    auth: {
        user: 'admin',
        pass: '<PASSWORD>'
    }
});

beforeAll(async () => {
    await stardog.createDatabase({
        database: testDb
    });

    await stardog.update({
        query: 'insert data {<urn:s> <urn:p> <urn:o>}'
    });
});

afterAll(async () => {
    await stardog.dropDatabase({
        database: testDb
    });
});

describe('databases', () => {
    test('create', async () => {
        await stardog.createDatabase({
            database: 'create'
        });

        expect(await stardog.existsDatabase({
            database: 'create'
        })).toBeTruthy();

        await stardog.dropDatabase({
            database: 'create'
        });
    });

    test('drop', async () => {
        await stardog.createDatabase({
            database: 'drop'
        });

        expect(await stardog.existsDatabase({
            database: 'drop'
        })).toBeTruthy();

        await stardog.dropDatabase({
            database: 'drop'
        });

        expect(await stardog.existsDatabase({
            database: 'drop'
        })).toBeFalsy();
    });

    test('size', async () => {
        expect(await stardog.sizeDatabase({
            database: testDb
        })).toBe(1);
    });

    test('list', async () => {
        expect(await stardog.listDatabases()).toContain(testDb);
    });

    test('exists', async () => {
        expect(await stardog.existsDatabase({
            database: testDb
        })).toBeTruthy();

        expect(await stardog.existsDatabase({
            database: testDb + '2'
        })).toBeFalsy();
    });
});

describe('queries', () => {
    test('ask', async () => {
        expect(await stardog.query({
            accept: 'text/boolean',
            query: 'ask {<urn:s> <urn:p> <urn:o>}'
        })).toBeTruthy();

        expect(await stardog.query({
            accept: 'text/boolean',
            query: 'ask {<urn:s> <urn:p> <urn:p>}'
        })).toBeFalsy();
    });

    test('select', async () => {
        expect(await stardog.query({
            query: 'select * where {?s ?p ?o}'
        })).toEqual({
            head: {vars: ['s', 'p', 'o']},
            results: {
                bindings: [{
                    s: {type: 'uri', value: 'urn:s'},
                    p: {type: 'uri', value: 'urn:p'},
                    o: {type: 'uri', value: 'urn:o'}
                }]
            }
        });
    });

    test('construct', async () => {
        expect(await stardog.query({
            query: 'construct {?s ?p ?o} where {?s ?p ?o}'
        })).toBe('\r\n<urn:s> <urn:p> <urn:o> .\r\n');
    });
});

describe('update queries', () => {
    test('insert', async () => {
        await stardog.update({
            query: 'insert data {<urn:insert> <urn:insert> <urn:insert>}'
        });

        expect(await stardog.query({
            accept: 'text/boolean',
            query: 'ask {<urn:insert> <urn:insert> <urn:insert>}'
        })).toBeTruthy();

        await stardog.update({
            query: 'delete data {<urn:insert> <urn:insert> <urn:insert>}'
        });
    });

    test('remove', async () => {
        await stardog.update({
            query: 'insert data {<urn:remove> <urn:remove> <urn:remove>}'
        });

        expect(await stardog.query({
            accept: 'text/boolean',
            query: 'ask {<urn:remove> <urn:remove> <urn:remove>}'
        })).toBeTruthy();

        await stardog.update({
            query: 'delete data {<urn:remove> <urn:remove> <urn:remove>}'
        });

        expect(await stardog.query({
            accept: 'text/boolean',
            query: 'ask {<urn:remove> <urn:remove> <urn:remove>}'
        })).toBeFalsy();
    });
});
{'fraction_non_alphanumeric': 0.1883825884408211, 'fraction_numerical': 0.00320279516669093, 'mean_word_length': 1.8376703841387856, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3444355', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2186, 'n_words': 425}