/**
 * Check the content of a cookie against a given value
 * @param  {String}   name          The name of the cookie
 * @param  {String}   falseCase     Whether or not to check if the value matches
 *                                  or not
 * @param  {String}   expectedValue The value to check against
 */
import {CustomExpect} from "../../common-helpers/custom-expect";
import {browser, $, $$, expect} from '@wdio/globals'

export default async function (name: string, falseCase: boolean, expectedValue: string) {
    /**
     * The cookie retrieved from the browser object
     * @type {Object}
     */
    const cookie = (await browser.getCookies(name))[0];
    CustomExpect.expectToBe(cookie.name, name, `Expected cookie name is "${name}", but actual cookie name is "${cookie.name}"`)

    if (falseCase) {
        CustomExpect.expectNotToContain(cookie.value, expectedValue, `Cookie value "${cookie.value}" contains "${expectedValue}"`)
    } else {
        CustomExpect.expectToContain(cookie.value, expectedValue, `Cookie value "${cookie.value}" does not contain "${expectedValue}"`)
    }
};

