Tell me the price of HMS 80:20 steel scrap on the east coast ofTurkey, during the first…
- User
Tell me the price of HMS 80:20 steel scrap on the east coast ofTurkey, during the first week of May 2023
- Assistant
I am an AI language model, and I cannot provide real-time data or predict future market prices. I would recommend checking a reliable source such as a financial news website or contacting a local scrap metal dealer for the most up-to-date pricing information.
- User
Do you have direct access to the internet?
- Assistant
As an AI language model, I don't have direct access to the internet or real-time data. I can only provide information and answer questions based on the pre-existing knowledge stored from the time my model was last trained, which is in 2021.
- User
How can I improve this?
export const getFutureDates = () => { const now = new Date(); const twoMondaysFromNow = startOfDay(addDays(nextMonday(now), 7)); const fourMondaysFromNow = startOfDay(addDays(twoMondaysFromNow, 14)); const twoFridaysFromTwoMondays = endOfDay( addBusinessDayRange(twoMondaysFromNow) ); const twoFridaysFromFourMondays = endOfDay( addBusinessDayRange(fourMondaysFromNow) ); const today = startOfDay(now); const twoFridaysFromToday = endOfDay(addBusinessDayRange(today));
return { twoMondaysFromNow, fourMondaysFromNow, twoFridaysFromFourMondays, twoFridaysFromTwoMondays, today, twoFridaysFromToday }; };
- Assistant
The function you provided seems to be generating an object with several calculated future dates based on business days, which I assume represent some specific milestones. Here's a simplified version of the function that's easier to read and understand.
import { startOfDay, endOfDay, addDays } from "date-fns"; import { nextMonday } from "date-fns/esm"; import { addBusinessDays } from "date-fns/esm"; export const getFutureDates = () => { const now = new Date(); const today = startOfDay(now); const getNextBusinessMonday = (date, weeksAhead = 1) => startOfDay(addDays(nextMonday(date), 7 * weeksAhead)); const getNextBusinessFriday = (date, weeksAhead = 1) => endOfDay(addBusinessDays(date, 5 * weeksAhead)); const twoMondaysFromNow = getNextBusinessMonday(now, 1); const fourMondaysFromNow = getNextBusinessMonday(now, 3); const twoFridaysFromTwoMondays = getNextBusinessFriday(twoMondaysFromNow, 1); const twoFridaysFromFourMondays = getNextBusinessFriday( fourMondaysFromNow, 1 ); const twoFridaysFromToday = getNextBusinessFriday(today, 1); return { today, twoMondaysFromNow, fourMondaysFromNow, twoFridaysFromTwoMondays, twoFridaysFromFourMondays, twoFridaysFromToday, }; }; - User
Can you write me unit tests for this:
const getCurrentOfficeAreas = ( formState: CreateOfficeFormState ): OfficeFormOfficeArea[] => { const areas = Object.keys(formState) .filter((key) => key.startsWith('office_area_')) .map((key) => { const id = parseInt(key.split('_')[2]); const areaState = formState[key];
let name: string | undefined; let capacity: number | undefined; for (const fieldKey in areaState) { const field = areaState[fieldKey]; if (field.type === 'plain_text_input') { name = field.value ?? undefined; } else if (field.type === 'number_input') { capacity = field.value ? parseInt(field.value) : undefined; } } return { id, name, capacity } as unknown as OfficeFormOfficeArea; }) .reduce((result: OfficeFormOfficeArea[], value, index, array) => { if (index % 2 === 0) { const officeArea = { id: array[index].id, name: array[index].name, capacity: array[index + 1].capacity }; result.push(officeArea); } return result; }, []);return areas; };
here is the formState parameters type:
export interface CreateOfficeFormState { [blockId: string]: { [actionId: string]: ViewStateValue; }; }
- Assistant
You can use a framework like Jest to write unit tests for this function. First, I will write a helper function to create test data to simplify the test cases:
const createTestData = (areaId, name, capacity) => ({ [`office_area_${areaId}`]: { [`name_field_${areaId}`]: { type: "plain_text_input", value: name }, [`capacity_field_${areaId}`]: { type: "number_input", value: capacity }, }, }); - User
I have this function, and I'm passing in the client from slack web api. How can I mock this for use in jest unit tests?
- Assistant
To mock the Slack Web API client for use in Jest unit tests, you can use Jest's mock functionality. I'll demonstrate a basic example. Let's assume you have a function you want to test called
sendMessage:// slackApi.js import { WebClient } from "@slack/web-api"; export const sendMessage = async (client, channel, text) => { const result = await client.chat.postMessage({ channel, text }); return result; };You can mock the
WebClientfrom "@slack/web-api" with Jest and provide a custom implementation for thechat.postMessagefunction. Then, you can write a test that verifies if the function was called with the correct input:// slackApi.test.js import { WebClient } from "@slack/web-api"; import { sendMessage } from "./slackApi"; jest.mock("@slack/web-api"); describe("sendMessage", () => { it("should call chat.postMessage with the correct channel and text", async () => { const mockPostMessage = jest.fn().mockResolvedValue({ ok: true }); WebClient.mockImplementation(() => { return { chat: { postMessage: mockPostMessage } }; }); const client = new WebClient("fake-token"); const channel = "C12345678"; const text = "Hello, Slack!"; await sendMessage(client, channel, text); expect(mockPostMessage).toHaveBeenCalledWith({ channel, text }); }); }); - User
I have this function:
import { deleteOfficeChatByName, getOfficeChatsToArchive } from '@/services/officeChat'; import { WebClient } from '@slack/web-api'; import { Callback, Context, Handler } from 'aws-lambda';
const webClient = new WebClient(process.env.SLACK_BOT_TOKEN);
export const officeChatArchiver: Handler = async ( event: any, context: Context, callback: Callback ) => { try { // Query the database for all channel names to archive const channels = await getOfficeChatsToArchive();
if (!channels.length) { callback(null, { statusCode: 200, body: 'No channels to archive' }); return; } // Archive each channel using the Slack Web API for (const channel of channels) { await webClient.conversations .info({ channel: channel.channel }) .then(async (info) => { if (!info.channel?.is_archived) { await webClient.conversations.archive({ channel: channel.channel }); console.log(`Channel ${channel.name} archived`); } else { console.log(`Channel ${channel.name} already archived`); } await deleteOfficeChatByName(channel.name); }); } callback(null, { statusCode: 200, body: 'Channels archived successfully.' }); - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.