Skip to content

Commit

Permalink
Merge pull request #2975 from juliemturner/version-4
Browse files Browse the repository at this point in the history
V4: Fix overwritten debug files
  • Loading branch information
juliemturner authored Mar 22, 2024
2 parents f35eeb0 + f23fde4 commit b4a2af7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
39 changes: 2 additions & 37 deletions debug/launch/graph.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,17 @@
import { Logger, LogLevel } from "@pnp/logging";
import { graphSetup } from "./setup.js";
import { getRandomString, stringIsNullOrEmpty } from "@pnp/core";
import "@pnp/graph/users";
import "@pnp/graph/files";
import { IDriveItemAdd, IDriveItemAddFolder, IFileUploadOptions, IItemOptions, IBundleDef } from "@pnp/graph/files";

declare var process: { exit(code?: number): void };

export async function Example(settings: any) {

const graph = graphSetup(settings);

const fileOptions: IFileUploadOptions = {
content: "This is some test content",
filePathName: "pnpTest.txt",
contentType: "text/plain;charset=utf-8",
};

const testUserName = settings.testing.testUser.substring(settings.testing.testUser.lastIndexOf("|") + 1);
const drives = await graph.users.getById(testUserName).drives();
let driveId = "";
if (drives.length > 0) {
driveId = drives[0].id;
}

// Create sample files
let folderId = "";
let child1Id = "";
let child2Id = "";
const testFolderName = `TestFolder_${getRandomString(4)}`;
const driveItemAdd: IDriveItemAddFolder = {
name: testFolderName,
};
const folder = await graph.users.getById(testUserName).drives.getById(driveId).root.children.addFolder(driveItemAdd);
if (folder != null) {
folderId = folder.id;
const testFileName = `TestFile_${getRandomString(4)}.json`;
const fo = JSON.parse(JSON.stringify(fileOptions));
fo.filePathName = testFileName;
const child1 = await graph.users.getById(testUserName).drives.getById(driveId).getItemById(folderId).upload(fo);
child1Id = child1.id;
fo.filePathName = `TestFile_${getRandomString(4)}.json`;
const child2 = await graph.users.getById(testUserName).drives.getById(driveId).getItemById(folderId).upload(fo);
child2Id = child2.id;
}
const users = await graph.users();

Logger.log({
data: folder,
data: users,
level: LogLevel.Info,
message: "List of Users Data",
});
Expand Down
4 changes: 2 additions & 2 deletions debug/launch/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { ITestingSettings } from "../../test/load-settings.js";
// add your debugging imports here and prior to submitting a PR git checkout debug/debug.ts
// will allow you to keep all your debugging files locally
// comment out the example
// import { Example } from "./sp.js";
import { Example } from "./graph.js";
import { Example } from "./sp.js";
// import { Example } from "./graph.js";

// setup the connection to SharePoint using the settings file, you can
// override any of the values as you want here, just be sure not to commit
Expand Down

0 comments on commit b4a2af7

Please sign in to comment.